Answers for "swift 5 range of string"

0

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")
}
Posted by: Guest on February-08-2021
0

find range of string swift

let string = "Please Click Here"
if let range = string.range(of: "Click") {
   print(range)

}
Posted by: Guest on October-20-2020

Code answers related to "Swift"

Browse Popular Code Answers by Language