I\'m used to do this in JavaScript:
var domains = \"abcde\".substring(0, \"abcde\".indexOf(\"cd\")) // Returns \"ab\"
Swift doesn\'t have t
Using String[Range
subscript you can get the sub string. You need starting index and last index to create the range and you can do it as below
let str = "abcde"
if let range = str.range(of: "cd") {
let substring = str[..
If you don't define the start index this operator ..<
, it take the starting index. You can also use str[str.startIndex..
str[..