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

 Live Demo

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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 22-Jun-2020

325 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements