どうも、ちょげ(@chogetarou)です。
文字列が全て大文字かどうか確認する方法を紹介します。
方法

文字列が全て大文字かどうか判定するには、ToUpper()を使います。
まず、文字列からToUpper()を呼び出します。
そして、ToUpper()の戻り値と元の文字列が同じかどうか比較します。
str == str.ToUpper()
上記の比較式は、文字列が全て大文字ならば「True」、全て大文字でなければ「False」を返します。
使用例
using System;
public class Example
{
public static void Main()
{
string text1 = "HELLO, CSHARP";
string text2 = "Hello, World";
Console.WriteLine(text1 == text1.ToUpper());
Console.WriteLine(text2 == text2.ToUpper());
}
}
/*
出力:
True
False
*/
コメント