Skip to content

Instantly share code, notes, and snippets.

@natecook1000
Forked from erica/split.swift
Created August 26, 2015 21:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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