importFoundation
println("Hello, World!")
//有如下一個(gè)數(shù)組,["type = iOS","Device = iPhone","count = 11344115@163.com","password = 12345"],將其中的內(nèi)容用“&”符號(hào)拼接成一個(gè)字符串
letarrary = ["type = iOS","Device = iPhone","count = 11344115@163.com","password = 12345"]
varstr =String()
forvari =0; i
ifi ==arrary.count-1{
str+=arrary[i]
}else{
str+=arrary[i]+"&"
}
}
print(str)
//arrary += & //(自己寫的,錯(cuò)誤的)
//arrary.insert("&",atIndex: 1)
//arrary.insert("&",atIndex: 3)
//arrary.insert("&",atIndex: 5)
//類名():表示初始化該變量
//定義一個(gè)字符串?dāng)?shù)組,遍歷該數(shù)組,如果數(shù)組中的字符串的長(zhǎng)度是4以上并且以“he”開頭就將該字符串放到一個(gè)新的數(shù)組當(dāng)中
letarrary1 = ["type = iOS","Device = iPhone","count = 11344115@163.com","password = 12345"]
varnewArrary = [String]()//初始化一個(gè)元素為字符串的空數(shù)組
forelementinarrary1{
if
element.lengthOfBytesUsingEncoding(4)>4&& element.hasPrefix("he"){
newArrary.append(element)
}
}
print(newArrary)