String.ToUpper メソッド ()
現在のカルチャの大文字と小文字の規則を使用して、この String のコピーを大文字で返します。
Overloads Public Function ToUpper() As String
[C#]
public string ToUpper();
[C++]
public: String* ToUpper();
[JScript]
public function ToUpper() : String;
戻り値
大文字の String 。
解説
このメソッドでは、現在のカルチャが考慮されます。詳細については、「 CultureInfo 」のトピックを参照してください。
使用例
[C#, C++] ToUpper メソッドを使用し、大文字と小文字を区別して String を比較するコード例を次に示します。
unsafe
{
// Null terminated ASCII characters in an sbyte array
String szAsciiUpper = null;
sbyte[] sbArr1 = new sbyte[] { 0x41, 0x42, 0x43, 0x00 };
// Instruct the Garbage Collector not to move the memory
fixed(sbyte* pAsciiUpper = sbArr1)
{
szAsciiUpper = new String(pAsciiUpper);
}
String szAsciiLower = null;
sbyte[] sbArr2 = { 0x61, 0x62, 0x63, 0x00 };
// Instruct the Garbage Collector not to move the memory
fixed(sbyte* pAsciiLower = sbArr2)
{
szAsciiLower = new String(pAsciiLower, 0, sbArr2.Length);
}
// Prints "ABC abc"
Console.WriteLine(szAsciiUpper + " " + szAsciiLower);
// Compare Strings - the result is true
Console.WriteLine("The Strings are equal when capitalized ? " +
(String.Compare(szAsciiUpper.ToUpper(), szAsciiLower.ToUpper())==0?"true":"false") );
// This is the effective equivalent of another Compare method, which ignores case
Console.WriteLine("The Strings are equal when capitalized ? " +
(String.Compare(szAsciiUpper, szAsciiLower, true)==0?"true":"false") );
}
[C++]
// Null terminated ASCII characters in a simple char array
char charArray3 [4] = { 0x41, 0x42, 0x43, 0x00 };
char* pstr3 = &charArray3[0];
String* szAsciiUpper = new String(pstr3);
char charArray4 [4] = { 0x61, 0x62, 0x63, 0x00 };
char* pstr4 = &charArray4[0];
String* szAsciiLower = new String(pstr4, 0, sizeof(charArray4));
// Prints "ABC abc"
Console::WriteLine(String::Concat(szAsciiUpper," ", szAsciiLower));
// Compare Strings - the result is true
Console::WriteLine(String::Concat("The Strings are equal when capitalized ? ",
(0 == String::Compare(szAsciiUpper->ToUpper(),szAsciiLower->ToUpper())?"TRUE":"FALSE") ));
// This is the effective equivalent of another Compare method, which ignores case
Console::WriteLine(String::Concat("The Strings are equal when capitalized ? ",
(0 == String::Compare(szAsciiUpper, szAsciiLower, true)?"TRUE":"FALSE") ) );
[Visual Basic, JScript] Visual Basic および JScript のサンプルはありません。C# および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
参照
String クラス | String メンバ | System 名前空間 | String.ToUpper オーバーロードの一覧 | ToLower