C# 程序检查字符串是否为全字词

C# 程序检查字符串是否为全字词

全语法包含了字母表中的所有 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# 程序检查字符串是否为全字词的详细内容,更多请关注编程之家其它相关文章!

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...