(1)遍历
(2)长度
(3)拼接
(4)插值
(5)大小写
(6)trim
(7)split
……等等
- var a = "你好"
- var b = String()
- a.isEmpty
- b = "xxxxxyyyyy"
- b.isEmpty
- //遍历
- for c in b {
- println(c)
- }
- //计算长度
- countElements(b)
- //拼接
- a += b
- //插值
- var strss = "a: \(a), b: \(b)"
- //比较
- let str_a = "abc"
- let str_b = "abc"
- str_a == str_b
- //字典序比较
- let str_c = "abd"
- str_b < str_c
- //前后缀
- str_b.hasPrefix("a")
- str_b.hasSuffix("c")
- //大小写转换
- str_b.uppercaseString
- str_b.lowercaseString
- //每个单词首字母大写
- let str_d = "i am a good person"
- str_d.capitalizedString
- //trim操作
- var s1 = " xx xx "
- s1.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
- s1.stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString:" "))
- //split操作
- var s2 = "i am a good boy"
- s2.componentsSeparatedByString(" ")
- s2.componentsSeparatedByCharactersInSet(NSCharacterSet(charactersInString: "a "))