
全语法包含了字母表中的所有 26 个字母。
下面,我们输入了一个字符串,并将检查它是否是全语法。 -
string str = "The quick brown fox jumps over the lazy dog";
现在,使用 ToLower()、isLetter() 和 Count() 函数检查字符串是否包含 not 的所有 26 个字母,因为 pangram 包含字母表的所有 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
以上就是C# 程序检查字符串是否为全字词的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号