I\'m used to do this in JavaScript:
var domains = \"abcde\".substring(0, \"abcde\".indexOf(\"cd\")) // Returns \"ab\"
Swift doesn\'t have t
Doing this in Swift is possible but it takes more lines, here is a function indexOf()
doing what is expected:
func indexOf(source: String, substring: String) -> Int? {
let maxIndex = source.characters.count - substring.characters.count
for index in 0...maxIndex {
let rangeSubstring = source.startIndex.advancedBy(index)..
This function is not optimized but it does the job for short strings.