Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a character is a vowel or consonant?

Tags:

c#

character

Is there a code to check if a character is a vowel or consonant? Some thing like char = IsVowel? Or need to hard code?

case ‘a’:
case ‘e’:
case ‘i’:
case ‘o’:
case ‘u’:
case ‘A’:
case ‘E’:
case ‘I’:
case ‘O’:
case ‘U’:
like image 594
Square Ponge Avatar asked Jul 20 '13 17:07

Square Ponge


People also ask

How do you check if a character is a consonant in C++?

If both isLowercaseVowel and isUppercaseVowel is true , the character entered is a vowel, if not the character is a consonant. The isalpha() function checks whether the character entered is an alphabet or not. If it is not, it prints an error message.

How do you check if a character is a vowel Java?

In Java, you use double quotes (" ") for strings and single quotes (' ') for characters. Now, to check whether ch is vowel or not, we check if ch is any of: ('a', 'e', 'i', 'o', 'u') . This is done using a simple if..else statement. We can also check for vowel or consonant using a switch statement in Java.

What kind of character is vowel?

A vowel is a syllabic speech sound pronounced without any stricture in the vocal tract. Vowels are one of the two principal classes of speech sounds, the other being the consonant. Vowels vary in quality, in loudness and also in quantity (length).

How do you check whether a character is vowel or not in Python?

Method 1: Users can use built-in functions to check whether an alphabet is vowel function in python or not. Step 2: Using built-in python functions like (lower(), upper()), determine whether the input is vowel or consonant. Step 3: If the character is a vowel, it should be printed.


1 Answers

You could do this:

char c = ...
bool isVowel = "aeiouAEIOU".IndexOf(c) >= 0;

or this:

char c = ...
bool isVowel = "aeiou".IndexOf(c.ToString(), StringComparison.InvariantCultureIgnoreCase) >= 0;

Once you add international support for things like éèe̋ȅëêĕe̊æøи etc. this string will get long, but the basic solution is the same.

like image 147
p.s.w.g Avatar answered Sep 18 '22 15:09

p.s.w.g