Last active
January 11, 2020 13:09
-
-
Save psksvp/bb84c28bee8753f4d0af791d79bf281d to your computer and use it in GitHub Desktop.
int index of Swift String
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
public extension String | |
{ | |
func intIndex(of s: String) -> Int? | |
{ | |
if let r = self.range(of: s) | |
{ | |
return self.distance(from: self.startIndex, to: r.lowerBound) | |
} | |
else | |
{ | |
return nil | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment