Check if a character is a vowel or consonant?

前端 未结 13 1157
别那么骄傲
别那么骄傲 2020-12-09 09:57

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’         


        
相关标签:
13条回答
  • 2020-12-09 10:50

    You can use "IsVowel" as you wanted. However the only thing is there is likely no default C# library or function that already does this out of the box, well if this is what you wanted. You will need to write a util method for this.

    bool a = isVowel('A');//example method call 
    
    public bool isVowel(char charValue){
        char[] vowelList = {'a', 'e', 'i', 'o', 'u'};
    
        char casedChar = char.ToLower(charValue);//handle simple and capital vowels
    
        foreach(char vowel in vowelList){
            if(vowel == casedChar){
                return true;
            }
        }
    
        return false;
    }    
    
    0 讨论(0)
提交回复
热议问题