>  기사  >  백엔드 개발  >  문자열이 전체 단어인지 확인하는 C# 프로그램

문자열이 전체 단어인지 확인하는 C# 프로그램

王林
王林앞으로
2023-08-30 22:09:07556검색

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

전체 문법에는 알파벳 26자가 모두 포함되어 있습니다.

아래에서는 문자열을 입력하여 전체 문법인지 확인하겠습니다. -

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

이제 ToLower(), isLetter(), Count() 함수를 사용하여 팬그램에 알파벳 26자가 모두 포함되어 있으므로 문자열에 not 의 26자가 모두 포함되어 있는지 확인하세요.

Example

다음 코드를 실행하여 문자열이 팬그램인지 확인할 수 있습니다.

라이브 데모

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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 tutorialspoint.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제