C# program to check for a string that contains all vowels

CsharpProgrammingServer Side Programming

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
raja
Published on 31-Aug-2018 15:45:54
Advertisements