DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4

Thread: Count Vowels

Hybrid View

  1. #1
    Join Date
    Dec 2007
    Posts
    10

    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 )

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,652
    Quote 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

  3. #3
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    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!

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    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

  1. Query works in Access, but not VB .NET
    By corygibbons in forum Database
    Replies: 6
    Last Post: 07-11-2007, 08:30 PM
  2. Help Semantic Tableaux Algorithm
    By dina86 in forum Java
    Replies: 0
    Last Post: 04-20-2007, 02:13 PM
  3. need to return total record count, but here is the trick...
    By barbarosa80503 in forum VB Classic
    Replies: 2
    Last Post: 10-28-2005, 03:33 PM
  4. count the number of vowels in a string
    By peskygal in forum VB Classic
    Replies: 6
    Last Post: 02-22-2005, 06:47 PM
  5. Re: word count!!! Faster, Leaner, Meaner!
    By James World in forum .NET
    Replies: 0
    Last Post: 08-13-2001, 04:22 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links