Skip to content

Instantly share code, notes, and snippets.

@didats
Created September 16, 2016 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save didats/3f99cec3faf112e012d5fb18e0307938 to your computer and use it in GitHub Desktop.
Save didats/3f99cec3faf112e012d5fb18e0307938 to your computer and use it in GitHub Desktop.
Finding index position of a string from a string with swift 3
// 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