
全语法包含了字母表中的所有 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# 程序检查字符串是否为全字词的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1435066.html
微信扫一扫
支付宝扫一扫