Extract Vowls from String

hans_cellc

Member
Joined
Mar 23, 2012
Messages
18
Programming Experience
Beginner
I have a string:
Mary has a little lamb.
I want to extract the vowels only in order and display in a label as follows:
aaaiea
I am working towards a list of constanants as well as follows:
mryhslttllmb
but want to start with the first part.
I have googled and found no such problems.
Can anyone please help.
 
There are various ways that you can do it. One option would be to create a String containing the five vowels, then use a For Each loop to loop through the Chars in your String and check whether that Char is in the vowel String. If it is, you can add that Char to a third String that starts empty. At the end of the loop, that third String will contain all the vowels from the first String. You simply negate the condition to get all the consonants instead.
 
This is what I got so far.
Private
Sub Button_Sort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Sort.Click

Dim strInput, strTemp As String, intCount As Integer = 0

Dim strList As String = ""
strInput = LCase(
Me.TextBox_Input.Text)

Do While intCount <= strInput.Length
strTemp = strInput.Substring(intCount, 1)

If strTemp = "a" OrElse strTemp = "e" OrElse strTemp = "i" OrElse strTemp = "o" OrElse strTemp = "u" Then
strList = strList + strTemp

End If
intCount += intCount

Loop

Me.Label_VowelOutput.Text = strList

End Sub
 
Ok changed the intCount as Iteger =1

works halfway but not all the way

I am sure it is something stupid

Private
Sub Button_Sort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Sort.Click


Dim strInput, strTemp As String, intCount As Integer = 1


Dim strList As String = ""

strInput = LCase(
Me.TextBox_Input.Text)


Do While intCount < strInput.Length + 1

strTemp = strInput.Substring(intCount, 1)


If strTemp = "a" OrElse strTemp = "e" OrElse strTemp = "i" OrElse strTemp = "o" OrElse strTemp = "u" Then

strList = strList + strTemp



End If

intCount += intCount


Loop


Me.Label_VowelOutput.Text = strList



End Sub
 
It would have been nice if you could have informed us up front that you already had code and shown us then so I didn't waste my time suggesting a different approach. Please provide ALL relevant information up front.

So, what's the problem? Does the code run? Does it do what you expect? If it doesn't run then what error(s) do you get? If it does not do what you expect then what exactly do you expect and what exactly does happen. Again, please provide all relevant information.
 
Sorry about that.
What happens is:
any duplication of vowels are not picked up, sometimes it does not pick up certain vowels and then in other words it will pick up no vowels.

I have even changed my code to the following but still exact same problem:

Private
Sub Button_Sort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Sort.Click

Dim strInput As String, intCount As Integer = 1

Dim ChaTemp As Char = ""

Dim ChaList As String = ""
strInput = LCase(
Me.TextBox_Input.Text)

Do While intCount <= strInput.Length
ChaTemp = strInput.Substring(intCount, 1)

If ChaTemp Like "a" OrElse ChaTemp Like "e" OrElse ChaTemp Like "i" OrElse ChaTemp Like "o" OrElse ChaTemp Like "u" Then
ChaList = ChaList + ChaTemp

End If
intCount += intCount

Loop

Me.Label_VowelOutput.Text = ChaList

Me.Button_Clear.Focus()

End Sub
 
I got it:
I used Chars() instead of Substring() and Voila:

Private
Sub Button_Sort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Sort.Click


Dim strInput As String, intCount As Integer = 0


Dim ChaTemp As Char = ""


Dim ChaList As String = ""

strInput = LCase(
Me.TextBox_Input.Text)


Do While intCount <= strInput.Length - 1

ChaTemp = strInput.Chars(intCount)


If ChaTemp Like "a" OrElse ChaTemp Like "e" OrElse ChaTemp Like "i" OrElse ChaTemp Like "o" OrElse ChaTemp Like "u" Then

ChaList = ChaList + ChaTemp



End If

intCount = intCount + 1


Loop


Me.Label_VowelOutput.Text = ChaList


Me.Button_Clear.Focus()



End Sub
 
Back
Top