如何在swift3中获取子字符串的范围?
let string = "Please Click Here"
我需要点击范围
答案 0 :(得分:12)
let string = "Please Click Here"
if let range = string.range(of: "Click") {
print(range)
}
答案 1 :(得分:6)
转换为NSString
和用户rangeOf
:
let string = "Please Click Here"
let range = (string as NSString).range(of: "Click", options: .caseInsensitive)
print(range)