C#程序检查包含所有元音的字符串
要检查所有元音,首先将条件设置为检查-
string res = str.Where(chk =< "aeiouAEIOU".Contains(chk)).Distinct();
上面,我们使用了字符串-
string str = "the quick brown fox jumps over the lazy dog";
现在,使用Any()方法检查字符串是否具有任何元音-
if(!res.Any())
Console.WriteLine("没有元音!");遍历字符串以获取元音-
示例
using System;
using System.Linq;
public class Program {
public static void Main() {
string str = "the quick brown fox jumps over the lazy dog";
var res = str.Where(chk =< "aeiouAEIOU".Contains(chk)).Distinct();
if(!res.Any())
Console.WriteLine("没有元音!");
foreach(var vowel in res)
Console.WriteLine("Your phrase contains vowel = {0}", vowel);
}
}输出结果
Your phrase contains vowel = e Your phrase contains vowel = u Your phrase contains vowel = i Your phrase contains vowel = o Your phrase contains vowel = a
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短