Skip to content

Instantly share code, notes, and snippets.

@JMatharu
Created May 7, 2020 21:46
Show Gist options
  • Save JMatharu/090e01876cd6b11ad55edaaafb82f4b7 to your computer and use it in GitHub Desktop.
Save JMatharu/090e01876cd6b11ad55edaaafb82f4b7 to your computer and use it in GitHub Desktop.
SplitString
extension StringProtocol {
var splitByString: [SubSequence] {
return self.split(separator: " ")
}
func seperateByCharacter(_ char: Character) -> [SubSequence] {
return self.split(separator: char)
}
}
"Hello! Swift String.".splitByString //["Hello!", "Swift", "String."]
"1997,Ford,E350".seperateByCharacter(",") //["1997", "Ford", "E350"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment