卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章64334本站已运行4115

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

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

全语法包含了字母表中的所有 26 个字母。

下面,我们输入了一个字符串,并将检查它是否是全语法。 -

string str = "The quick brown fox jumps over the lazy dog";

现在,使用 ToLower()、isLetter() 和 Count() 函数检查字符串是否包含 not 的所有 26 个字母,因为 pangram 包含字母表的所有 26 个字母。

< h2

示例

您可以尝试运行以下代码来检查字符串是否为pangram。

现场演示< /p>

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

卓越飞翔博客
上一篇: 动态类型变量和对象类型变量有什么区别?
下一篇: 基于Python的图像增强技术
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏