C#程序检查字符串是否为panagram
七巧板具有一个字母的所有26个字母。
在下面,我们输入了一个字符串,并将检查它是否是Pangram-
string str = "The quick brown fox jumps over the lazy dog";
现在,检查使用ToLower(),isLetter()并且Count()方法字符串已经全部没有因为全字母短句拥有所有的字母表中的26个字母的26个字母。
示例
您可以尝试运行以下代码来检查字符串是否为pangram。
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;
}
}
}输出结果
True: "The quick brown fox jumps over the lazy dog" is pangram
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短