MattP also had a neat way of getting both vowels and cons..
vb Code:
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim testString As String = "Rather than writing out each of the consonants I made a method to check for the vowels and replace them with an empty string"
Dim vowels = ExtractVowels(testString, True)
Dim cons = ExtractConsontant(testString, True)
Console.WriteLine("Counted " & vowels.Length & " vowels. They are " & vowels.Trim.Replace(" ", String.Empty)) ' vowels list
Console.WriteLine("Counted " & cons.Length & " Cons. They are " & cons.Trim.Replace(" ", String.Empty)) ' cons list
End Sub
Private Shared Function ExtractVowels(inputString As String, includeY As Boolean) As String
Dim pattern As String = If(includeY, "[^aeiouyAEIOUY$]", "[^aeiouAEIOU$]")
Return String.Join(Nothing, System.Text.RegularExpressions.Regex.Split(inputString, pattern))
End Function
Private Shared Function ExtractConsontant(inputString As String, includeY As Boolean) As String
Dim pattern As String = If(includeY, "[aeiouyAEIOUY]", "[aeiouAEIOU]")
Return System.Text.RegularExpressions.Regex.Replace(inputString, pattern, String.Empty).Replace(" ", String.Empty)
End Function
from here