Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

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")
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #find #range #string #string #swift
ADD COMMENT
Topic
Name
9+7 =