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("No vowels!");循环遍历字符串以获取元音 -
示例
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("No vowels!");
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP