To check if a character is a vowel you can use the following extension method.

Extension Method in C#

public static bool IsVowel(this char input)
{
	return (input == 'a' || input == 'e' || input == 'i' || input == 'o' || input == 'u') || (input == 'A' || input == 'E' || input == 'I' || input == 'O' || input == 'U');
}

Extension Method in VB.NET

Public Shared Function IsVowel(this ByVal input As Char) As Boolean
        Return (((input = Microsoft.VisualBasic.ChrW(97))  _
                    OrElse ((input = Microsoft.VisualBasic.ChrW(101))  _
                    OrElse ((input = Microsoft.VisualBasic.ChrW(105))  _
                    OrElse ((input = Microsoft.VisualBasic.ChrW(111))  _
                    OrElse (input = Microsoft.VisualBasic.ChrW(117))))))  _
                    OrElse ((input = Microsoft.VisualBasic.ChrW(65))  _
                    OrElse ((input = Microsoft.VisualBasic.ChrW(69))  _
                    OrElse ((input = Microsoft.VisualBasic.ChrW(73))  _
                    OrElse ((input = Microsoft.VisualBasic.ChrW(79))  _
                    OrElse (input = Microsoft.VisualBasic.ChrW(85)))))))
    End Function

One thought on “How to check if a character is a vowel in C# or VB.NET”

Leave a Reply