美文网首页
Swift 字符串截取

Swift 字符串截取

作者: 吉林天师 | 来源:发表于2019-10-18 16:22 被阅读0次

代码

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..<str.endIndex] // 截头
debugPrint("q",sub4)

结果

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

相关文章

网友评论

      本文标题:Swift 字符串截取

      本文链接:https://www.haomeiwen.com/subject/iytwmctx.html