-
-
Save aciidgh/598de079d8ced0891f7a to your computer and use it in GitHub Desktop.
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 trimBackTo(boundary: Character) -> String { | |
if isEmpty {return ""} | |
if self[endIndex.predecessor()] == boundary { return "" } | |
return characters.split(boundary).map(String.init).last! | |
} | |
func trimUpTo(boundary: Character) -> String { | |
if isEmpty { return "" } | |
if self[startIndex] == boundary {return String(self[startIndex])} | |
return characters.split(boundary, maxSplit: 1, allowEmptySlices: false).map(String.init).first! | |
} | |
} |
Author
aciidgh
commented
Dec 28, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment