How to Count Number of Vowels in a String
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 'String Manipulation - How to Count Number of Vowels in a String Option Explicit Public Function VowelCount(ByVal strExpression As String) As Long Dim sVowels() As Variant Dim iResult As Integer, I As Integer Dim lLength As Long sVowels() = Array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U") lLength = Len(strExpression) For lLength = 1 To lLength For I = LBound(sVowels) To UBound(sVowels) 'Check whether the character is a vowel If Mid$(strExpression, lLength, 1) = sVowels(I) Then 'if the character is a vowel iResult = iResult + 1 End If Next I Next lLength VowelCount = iResult End Function |