모든 모음을 확인하려면 먼저 확인 조건을 설정하십시오 -
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