imzyf / ios-swift-learning-notes

📝 iOS Swift Learning Notes - see Issues
MIT License
0 stars 0 forks source link

String 替换、过滤、去掉空格、分割、拼接、字符串截取 #47

Closed imzyf closed 6 years ago

imzyf commented 6 years ago

http://www.jianshu.com/p/26d9201ef479

let s = " / 2 3 4 ? / "
    // 替换
    print("空格替换成-:", s.replacingOccurrences(of: " ", with: "-"))
    // 过滤
    print("空格过滤掉:", s.replacingOccurrences(of: " ", with: ""))
    // 去首尾空格
    print("去掉空格:", s.trimmingCharacters(in: .whitespaces))
    // 分割
    print("分割:", s.components(separatedBy: "/"))
    // 拼接
    let a = ["1", "2", "3"]
    print("拼接:", a.joined(separator: "-"))
imzyf commented 6 years ago

repeat