警告:'substring(from:)' is deprecated: Please use String slicing subscript with a 'partial range from' operator.
获取字符串子串
Swift 3.0中 的写法
let str = "我们一起去飞"
let s3 = str.substring(with:"我们".endIndex)
Swift 4.0中 的写法
let str = "我们一起去飞"
let s3 = String(str["我们".endIndex...])
相关方法:
let newStr = String(str[..<index]) // = str.substring(to: index) In Swift 3
let newStr = String(str[index...]) // = str.substring(from: index) In Swif 3
let newStr = String(str[range]) // = str.substring(with: range) In Swift 3
字符串相关警告:
警告:'characters' is deprecated: Please use String or Substring directly
str.characters.count//获取字符串的长度
解决:
let str = "hello world" str.count