1.使用Range截取字符串
let text = "1234567890"
let indexStart = text.startIndex
let index = text.index(indexStart, offsetBy: 6)
print(String(text[indexStart..<index]))
//输出结果:123456
2.使用subString提供的方法截取字符串
let text = "1234567890"
let result:Substring = text.dropFirst(0).prefix(6)
//或
//let result:Substring = text.prefix(6)
print(String(result))
//输出结果:
网友评论