Created
September 16, 2016 01:17
-
-
Save didats/3f99cec3faf112e012d5fb18e0307938 to your computer and use it in GitHub Desktop.
Finding index position of a string from a string with swift 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// case sensitive | |
func findPosition(of: String, from: String) -> Int { | |
if let range : Range<String.Index> = from.range(of: of) { | |
return from.distance(from: from.startIndex, to: range.lowerBound) | |
} | |
return -1 | |
} | |
findPosition(of: "adi", from: "Didats Triadi") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment