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