// 1, 字符串的截取
let url = "www:xiaoyu.com"
// 1.1 方式一:将string类型转成nsstring as NSString
let header = (url as NSString).substring(to: 3)
let range = NSMakeRange(4, 8)
let middle = (url as NSString).substring(with: range)
// 1.2 方式二:直接使用string
let headerIndex = url.index(url.startIndex, offsetBy: 3)
let header1 = url.substring(to: headerIndex)
let startIndex = url.index(url.startIndex, offsetBy: 4)
let endIndex = url.index(url.startIndex, offsetBy: 10)
let range2 = Range(startIndex..<endIndex)
let middle2 = url.substring(with: range2)
let strart3 = url.index(url.startIndex, offsetBy: 11)
let end3 = url.index(url.startIndex, offsetBy: 14)
let rang3 = Range(strart3..<end3)
let endStr = url.substring(with: rang3)
swift-字符串的截取
最新推荐文章于 2021-07-16 10:17:25 发布