Created
August 3, 2019 23:46
-
-
Save piyushdec/a84743cb42115c2cedd90ee76ba3329f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//https://medium.com/@sorenlind/three-ways-to-enumerate-the-words-in-a-string-using-swift-7da5504f0062 | |
extension String { | |
func words() -> [String] { | |
let range = self.startIndex..<self.endIndex | |
var words = [String]() | |
self.enumerateSubstrings(in: range, options: NSString.EnumerationOptions.byWords) { (substring, _, _, _) -> () in | |
words.append(substring ?? "") | |
} | |
return words | |
} | |
} | |
var st = "ajdlkkl . d," | |
print(st.words()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment