
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check If String Is Panagram in C#
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.
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
Advertisements