Swift 字符串截取

代码

let str = "1234567890ASDFGHJKLoiuytrewq"
let endStr1 = str.prefix(10) // 抓头
debugPrint(endStr1)
debugPrint(str.suffix(10)) // 去尾

let index2 = str.index(str.startIndex, offsetBy: 5) // 
let sub4 = str[index2..

结果

"1234567890"
"Loiuytrewq"
"q","67890ASDFGHJKLoiuytrewq"

你可能感兴趣的:(Swift 字符串截取)