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
let string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi enim lacus, ullamcorper in gravida a, semper id dolor. Mauris quis metus id" | |
extension String { | |
func split(separator: Character, maxSplit: Int = .max, allowEmptySlices: Bool = false) -> [String] { | |
return characters.split(separator, maxSplit: maxSplit, allowEmptySlices: allowEmptySlices).map(String.init) | |
} | |
} | |
let words = try string.split(" ") | |
let counts = words.map { $0.characters.count } | |
print(counts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment