Click here to Skip to main content
15,073,496 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Below is what I have for counting vowels in a sentence how do I get it to count the number of words in the sentence? After I get the total word count I need a message box to show the count then reverse the sentence and put it in backwards into the text box.

Public Function CountVowels(ByVal strSentence As String, ByRef intVowels As Integer) As Integer
        Dim intIndex As Integer
        Dim strCurrentLetter As String

        For intIndex = 0 To strSentence.Length - 1
            strCurrentLetter = strSentence.Substring(intIndex, 1)
            If strCurrentLetter = "a" Or strCurrentLetter = "e" Or strCurrentLetter = "i" Or strCurrentLetter = "o" Or strCurrentLetter = "u" Then
                intVowels += 1
            End If
        Return intVowels
    End Function

1 solution

The easiest way is to use string.Split:
Dim text As String = "the quick, brown fox,jumps over the lazy dog"
Dim words As String() = text.Split(New Char() {" "C, ","C, "."C, "?"C, "!"C}, StringSplitOptions.RemoveEmptyEntries)
Dim i As Integer = words.Length

You can then rebuild the parts backwards as a sentence and display that in a MessageBox. I won't give you that code: You should do some of your own homework! :laugh:

[edit]Added rebuild comment - OriginalGriff[/edit]
Anthony Bond 21-May-11 10:30am
Thank you. I've figured most of it out just have been getting stuck on the details. Lets just say I don't have enough learning material.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900