Skip to content

Instantly share code, notes, and snippets.

@Denismih
Created November 15, 2018 12:39
Show Gist options
  • Save Denismih/6873a19cbc96d91f18489ba94c0176bb to your computer and use it in GitHub Desktop.
Save Denismih/6873a19cbc96d91f18489ba94c0176bb to your computer and use it in GitHub Desktop.
string slice
extension String {
func slice(from: String, to: String) -> String? {
return (range(of: from)?.upperBound).flatMap { substringFrom in
(range(of: to, range: substringFrom..<endIndex)?.lowerBound).map { substringTo in
String(self[substringFrom..<substringTo])
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment