Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C# program to check for a string that contains all vowels
To check for all vowels, firstly set the condition to check −
string res = str.Where(chk =< "aeiouAEIOU".Contains(chk)).Distinct();
Above, we have used the string −
string str = "the quick brown fox jumps over the lazy dog";
Now, using the Any() method checks whether the string has any vowels or not −
if(!res.Any())
Console.WriteLine("No vowels!");
Loop through the string to get the vowels −
Example
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);
}
}
Output
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
Advertisements
