Alright so i'm writing a program, and i need to count the number of times a word begins with a letter.
Alright so now the message box displays the correct conversion to pig latin, and will count the number of words in the string, but i need to be pointed in the right direction as to how i could.
1. Count the number of words that begin with a vowel coming from the text box. I was looking around and learned how to count all the vowels in the string, but i dont know what i need to do to search the first char then skip the string and goto the next. Can anyone point me in the right direction?
Code:
Public Class frmPigLatin
Private Sub btnTranslate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTranslate.Click
Dim strChar1 As String
Dim strInput As String
Dim strOutput As String = ""
Dim strWords As String() 'Makes an empty array
Dim i As Integer
Dim strConversion As String
strInput = txtEnterWords.Text
'Split the text into an array of words
strWords = Split(strInput, " ")
For i = LBound(strWords) To UBound(strWords)
strChar1 = strWords(i).Substring(0, 1)
Select Case strChar1.ToUpper
Case "A", "E", "I", "O", "U"
strWords(i) = (strWords(i) & "WAY")
Case Else
strWords(i) = (strWords(i).Substring(1) & strChar1 & "AY")
End Select
'Loop through each word...
Next i
'Put the words back together.
strConversion = String.Join(" ", strWords)
MessageBox.Show(strConversion _
& vbCrLf & "There are " & nbrWords() & " words in the box.", "Pig Latin")
End Sub
Private Function nbrWords()
Dim strLength As String
Dim strWhole As String
Dim strCounter As String
Dim x As Integer
'Trim spaces on front and end.
strWhole = Trim(Me.txtEnterWords.Text)
If strWhole = "" Then
MsgBox("Please enter words")
End If
'Put the length of strWhole in the strLength variable
strLength = Len(strWhole)
strCounter = 1
Dim currentLetter As String
Dim prevLetter As String
For x = 2 To strLength
currentLetter = Mid(strWhole, x, 1)
prevLetter = Mid(strWhole, x - 1, 1)
If currentLetter = Chr(32) And prevLetter <> Chr(32) Then
strCounter = strCounter + 1
End If
Next
Return strCounter
End Function
1. Count the number of words that begin with a vowel coming from the text box. I was looking around and learned how to count all the vowels in the string, but i dont know what i need to do to search the first char then skip the string and goto the next. Can anyone point me in the right direction?
Comment