C# program to check if string is panagram or not

CsharpServer Side ProgrammingProgramming

A pangram has all the 26 letters of an alphabet.

Below, we have entered a string, and will check whether it is a pangram or not −

string str = "The quick brown fox jumps over the lazy dog";

Now, check using the ToLower(), isLetter() and Count() functions that the string has all the 26 letters of not since pangram has all the 26 letters of an alphabet.

Example

You can try to run the following code to check whether a string is pangram or not.

Live Demo

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Demo {
   public class Program {
      public static void Main(string []arg) {
         string str = "The quick brown fox jumps over the lazy dog";
         Console.WriteLine("{0}: \"{1}\" is pangram", checkPangram(str), str);
         Console.ReadKey();
      }
      static bool checkPangram(string str) {
         return str.ToLower().Where(ch => Char.IsLetter(ch)).GroupBy(ch => ch).Count() == 26;
      }
   }
}

Output

True: "The quick brown fox jumps over the lazy dog" is pangram
raja
Published on 24-Jul-2018 14:50:22
Advertisements