Created
November 15, 2018 12:39
-
-
Save Denismih/6873a19cbc96d91f18489ba94c0176bb to your computer and use it in GitHub Desktop.
string slice
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
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