count the number of vowels in a string


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: count the number of vowels in a string

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Posts
    6

    count the number of vowels in a string

    hello.. how am i to code a program tht will accept a line of string from a user and count the number of vowels in tht particular string? plz help

  2. #2
    Join Date
    Dec 2004
    Posts
    110
    Here is an example of what you could do, though I'm sure some of the professionals on this forum could do something more elegant:

    Put a command button and a textbox on a form and place this code in the click event for the command button.

    ------------------------------------------------------------------------

    HTML Code:
    Dim intCounter As Integer
    Dim intVowels As Integer
    Dim strLetter As String
    
    ' count vowels in a string
    
    ' search for a
    For intCounter = 1 To Len(Text1.Text)
        strLetter = LCase(Mid(Text1.Text, intCounter, 1))
        Select Case strLetter
            Case Is = "a"
               intVowels = intVowels + 1
            Case Is = "e"
               intVowels = intVowels + 1
            Case Is = "i"
               intVowels = intVowels + 1
            Case Is = "o"
               intVowels = intVowels + 1
            Case Is = "u"
               intVowels = intVowels + 1
            Case Else:
                ' do nothing
        End Select
            
    Next intCounter
    
    MsgBox "Number of vowels: " & intVowels

  3. #3
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    just a small change in Lithic code:

    select case strLetter
    case "a","b","c","d","e"
    intvowels=intvowels+1
    end select

    Marco

  4. #4
    Join Date
    Dec 2004
    Posts
    110
    Thanks for that Marco, this site is great for learning and refining techniques.
    Cheers,
    Lithic.

  5. #5
    Join Date
    Feb 2005
    Posts
    6

    thanks

    thank you so much guys for helping me out.. appreciate it =)

  6. #6
    Join Date
    Jun 2004
    Location
    Houston area
    Posts
    557
    ummmm.............marco! She wanted the number of VOWELS!
    b,c,and d aren't vowels! :-

    select case strLetter
    case "a","e","i","o","u"
    intvowels=intvowels+1
    end select

    L
    A balanced diet is a cookie in each hand.

  7. #7
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    ops... too much time using programming languages. I need a break, I am alraedy making too many spelling mistekes.
    Thanks Laurel.
    Well, you told me I WAS funny

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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center