C# program to check if string is panagram or not


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

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 19-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements