[Solved] Counting Vowels in Swift [closed]


You could do something like this:

extension String {
    var numberOfVowels: Int {
        let vowels = "aeiou"
        let vowelsSet = NSCharacterSet(charactersInString: vowels)
        let strippedComponents = lowercaseString.componentsSeparatedByCharactersInSet(vowelsSet)
        let stripped = strippedComponents.joinWithSeparator("")
        return characters.count - stripped.characters.count
    }
}

"Hello".numberOfVowels

5

solved Counting Vowels in Swift [closed]