如何获得swift3中的子串范围?

时间:2016-10-30 10:44:06

标签: ios xcode swift3

如何在swift3中获取子字符串的范围?

 let string  = "Please Click Here"

我需要点击范围

2 个答案:

答案 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)