- 截取 String
var str = "(aaa)哈哈"
let index = str.range(of: ")")!
let preStr = str.prefix(upTo: index.upperBound) // “(aaa)”
let sufStr = str.suffix(from: index.upperBound)// “哈哈”
- 遍历 String
let str = "abcdefghhi"
for cha in str {
print(cha)
}
var str = "(aaa)哈哈"
let index = str.range(of: ")")!
let preStr = str.prefix(upTo: index.upperBound) // “(aaa)”
let sufStr = str.suffix(from: index.upperBound)// “哈哈”
let str = "abcdefghhi"
for cha in str {
print(cha)
}