swift 4 字符串截取

截取某字符串的前10個字符串spa

let sub1 = str.prefix(10)

截取某字符串的後10個字符串code

let str1 = str.suffix(10)

也能夠換種寫法blog

let index2 = str.index(str.endIndex, offsetBy: -10)
let sub4 = str[index2..<str.endIndex]

截取某字符串的第3個字符到第6個字符範圍的字符串字符串

let index3 = str.index(str.startIndex, offsetBy: 3)
let index4 = str.index(str.startIndex, offsetBy: 6)
let sub4 = str[index3..<index4]
相關文章
相關標籤/搜索