range of string in swift code example
Example 1: how can i find range of a string in another string swift
let str = "abcde"
if let range = str.range(of: "cd") {
let substring = str[..<range.lowerBound] // or str[str.startIndex..<range.lowerBound]
print(substring) // Prints ab
}
else {
print("String not present")
}
Example 2: find range of string swift
let string = "Please Click Here"
if let range = string.range(of: "Click") {
print(range)
}