swift 字符串部分操作
程序员文章站
2022-06-08 13:54:55
...
let ss = "<p>你a好b呀!</p>"
//替换处理
print("去掉a: \(ss.replacingOccurrences(of: "a",with: ""))")
print("去掉标签 \(ss.replacingOccurrences(of: "<p>",with: ""))")
print("去掉标签 \(ss.replacingOccurrences(of: "</p>",with: ""))")
print("去掉首尾空格: \(ss.trimmingCharacters(in: .whitespaces))")
let b = ["aa","bb","cc"]
print("字符串拼接 \(b.joined(separator: "-"))")
let dataString = "2019.03.28"
let index = dataString.index(dataString.endIndex, offsetBy: -2)
let suffix = dataString.substring(from: index)
let indexa = dataString.index(dataString.startIndex, offsetBy: 2)
let prefix = dataString.substring(to: indexa)
let startRange = dataString.index(dataString.startIndex, offsetBy: 5)
let endRange = dataString.index(dataString.startIndex, offsetBy: 7)
let middle = dataString.substring(with: Range(startRange..<endRange))
上一篇: bootStrap-table之全选反选
下一篇: 快速了解 ——二