iOS swift字符串、数组

//显式字符串写法
var str = "Hello, playground"
//隐式字符串
var s:String = "abcd"
//字符串拼接
s = "打算发的说法是\(18) s=\(s)"
var s2 = s + str
s2 += "a"

//判断相等
s == s2
s.hasPrefix("a")
s2.hasSuffix("a")

//判断是否是空字符串
s = ""
s.isEmpty

//分割字符串
s = "a,b,c,d"
s.components(separatedBy: ",")

//数组
//隐式
let arr = [1,2,3,4]
//显式
let arr2:[Int] = [3,4,1,3]

let arr3:[String] = ["a", "b", "c"]

//初始化可变数组
//声明一个可变的数组
var arr4:[String] = ["a", "b", "c"]
arr4.append("d")
//编历数组
for item in arr4 {
    print(item)
}
for i in 0..

你可能感兴趣的:(iOS swift字符串、数组)