Skip to content

Instantly share code, notes, and snippets.

@psksvp
Last active January 11, 2020 13:09
Show Gist options
  • Save psksvp/bb84c28bee8753f4d0af791d79bf281d to your computer and use it in GitHub Desktop.
Save psksvp/bb84c28bee8753f4d0af791d79bf281d to your computer and use it in GitHub Desktop.
int index of Swift String
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