-
Count Vowels
Ok, everyone get ready to laugh.
I need to be able to count the number of vowels in a string, and display the count in a textbox. How would I do that?
(Please don't ask why )
-
 Originally Posted by RichardGR
(Please don't ask why  )
Ok, I won't (but, I really would like to know. )
Anyway, try something like this
Code:
Private Function VowelCount(ByVal InputString As String) As Long
Dim Vowel(11) As String
Dim NumberOfVowels As Long
Dim VowelFlag As Long
Dim LengthOfString As Long
Dim i As Long
'arrary of possible vowels
Vowel(0) = "a"
Vowel(1) = "i"
Vowel(2) = "o"
Vowel(3) = "u"
Vowel(4) = "e"
Vowel(5) = "y"
Vowel(6) = "A"
Vowel(7) = "I"
Vowel(8) = "O"
Vowel(9) = "U"
Vowel(10) = "E"
Vowel(11) = "Y"
LengthOfString = Len(InputString)
For VowelFlag = 1 To LengthOfString
For i = 0 To 11
If Mid(InputString, VowelFlag, 1) = Vowel(i) Then
NumberOfVowels = NumberOfVowels + 1
End If
Next
Next
VowelCount = NumberOfVowels
MsgBox VowelCount
End Function
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
Here's another:
Code:
Dim I As Integer
Dim nVowels As Integer
Dim Vowels As String
Dim InputString As String
Vowels = "aeiou"
InputString = LCase(InputString)
For I = 1 To Len(InputString)
If InStr(Vowels, Mid(InputString, I, 1)) Then
nVowels = nVowels + 1
End If
Next
MsgBox nVowels
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
One more:
Code:
Dim exp As RegExp
Dim Matches As MatchCollection
Dim nVowels As Integer
Dim InputString As String
Set exp = New RegExp
With exp
.Pattern = "[aeiou]"
.Global = True
.IgnoreCase = True
Set Matches = .Execute(InputString)
End With
nVowels = Matches.Count
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
Similar Threads
-
By corygibbons in forum Database
Replies: 6
Last Post: 07-11-2007, 08:30 PM
-
Replies: 0
Last Post: 04-20-2007, 02:13 PM
-
By barbarosa80503 in forum VB Classic
Replies: 2
Last Post: 10-28-2005, 03:33 PM
-
By peskygal in forum VB Classic
Replies: 6
Last Post: 02-22-2005, 06:47 PM
-
By James World in forum .NET
Replies: 0
Last Post: 08-13-2001, 04:22 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks