importFoundation
println("Hello, World!")
//有如下一个数组,["type = iOS","Device = iPhone","count = 11344115@163.com","password = 12345"],将其中的内容用“&”符号拼接成一个字符串
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 += & //(自己写的,错误的)
//arrary.insert("&",atIndex: 1)
//arrary.insert("&",atIndex: 3)
//arrary.insert("&",atIndex: 5)
//类名():表示初始化该变量
//定义一个字符串数组,遍历该数组,如果数组中的字符串的长度是4以上并且以“he”开头就将该字符串放到一个新的数组当中
letarrary1 = ["type = iOS","Device = iPhone","count = 11344115@163.com","password = 12345"]
varnewArrary = [String]()//初始化一个元素为字符串的空数组
forelementinarrary1{
if
element.lengthOfBytesUsingEncoding(4)>4&& element.hasPrefix("he"){
newArrary.append(element)
}
}
print(newArrary)