Answers for "swift string search index"

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 "Swift"

Browse Popular Code Answers by Language