csharp 返回字符串中元音或辅音的数量。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 返回字符串中元音或辅音的数量。相关的知识,希望对你有一定的参考价值。

int VowelCount(this string value)
{
    var vowels = new[] { 'a', 'e', 'i', 'o', 'u' };
    return value.Count(ch => vowels.Contains(ch));
}

int ConsonantCount(this string value)
{
    var consonant = new[] { 'b', 'c', 'd', 'f', 'g', 'h',
                            'j', 'k', 'l', 'm', 'n', 'p',
                            'q', 'r' , 's', 't', 'v', 'w',
                            'x', 'y', 'z' };
    return value.Count(ch => consonant.Contains(ch));
}

以上是关于csharp 返回字符串中元音或辅音的数量。的主要内容,如果未能解决你的问题,请参考以下文章