Answers for "how can i find range of a string in another string swift"

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

Code answers related to "how can i find range of a string in another string swift"

Code answers related to "Swift"

Browse Popular Code Answers by Language