TextInfo.ToUpper 方法

定義

將指定字元或字串轉換為大寫。

多載

ToUpper(Char)

將指定字元轉換為大寫。

ToUpper(String)

將指定字串轉換為大寫。

範例

下列程式代碼範例會根據英文 (美國) 文化特性變更字串的大小寫,並使用文化特性名稱 en-US。

using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Defines the String* with mixed casing.
   String^ myString = "wAr aNd pEaCe";
   
   // Creates a TextInfo based on the S"en-US" culture.
   CultureInfo^ MyCI = gcnew CultureInfo( "en-US",false );
   TextInfo^ myTI = MyCI->TextInfo;
   
   // Changes a String* to lowercase.
   Console::WriteLine( "\"{0}\" to lowercase: {1}", myString, myTI->ToLower( myString ) );
   
   // Changes a String* to uppercase.
   Console::WriteLine( "\"{0}\" to uppercase: {1}", myString, myTI->ToUpper( myString ) );
   
   // Changes a String* to titlecase.
   Console::WriteLine( "\"{0}\" to titlecase: {1}", myString, myTI->ToTitleCase( myString ) );
}

/*
This code produces the following output.

S"wAr aNd pEaCe" to lowercase: war and peace
S"wAr aNd pEaCe" to uppercase: WAR AND PEACE
S"wAr aNd pEaCe" to titlecase: War And Peace

*/
using System;
using System.Globalization;

public class SamplesTextInfo  {

   public static void Main()  {

      // Defines the string with mixed casing.
      string myString = "wAr aNd pEaCe";

      // Creates a TextInfo based on the "en-US" culture.
      TextInfo myTI = new CultureInfo("en-US",false).TextInfo;

      // Changes a string to lowercase.
      Console.WriteLine( "\"{0}\" to lowercase: {1}", myString, myTI.ToLower( myString ) );

      // Changes a string to uppercase.
      Console.WriteLine( "\"{0}\" to uppercase: {1}", myString, myTI.ToUpper( myString ) );

      // Changes a string to titlecase.
      Console.WriteLine( "\"{0}\" to titlecase: {1}", myString, myTI.ToTitleCase( myString ) );
   }
}

/*
This code produces the following output.

"wAr aNd pEaCe" to lowercase: war and peace
"wAr aNd pEaCe" to uppercase: WAR AND PEACE
"wAr aNd pEaCe" to titlecase: War And Peace

*/
Imports System.Globalization

Public Class SamplesTextInfo

   Public Shared Sub Main()

      ' Defines the string with mixed casing.
      Dim myString As String = "wAr aNd pEaCe"

      ' Creates a TextInfo based on the "en-US" culture.
      Dim myTI As TextInfo = New CultureInfo("en-US", False).TextInfo

      ' Changes a string to lowercase.
      Console.WriteLine("""{0}"" to lowercase: {1}", myString, myTI.ToLower(myString))

      ' Changes a string to uppercase.
      Console.WriteLine("""{0}"" to uppercase: {1}", myString, myTI.ToUpper(myString))

      ' Changes a string to titlecase.
      Console.WriteLine("""{0}"" to titlecase: {1}", myString, myTI.ToTitleCase(myString))

   End Sub

End Class


'This code produces the following output.
'
'"wAr aNd pEaCe" to lowercase: war and peace
'"wAr aNd pEaCe" to uppercase: WAR AND PEACE
'"wAr aNd pEaCe" to titlecase: War And Peace

ToUpper(Char)

來源:
TextInfo.cs
來源:
TextInfo.cs
來源:
TextInfo.cs

將指定字元轉換為大寫。

public:
 virtual char ToUpper(char c);
public:
 char ToUpper(char c);
public virtual char ToUpper (char c);
public char ToUpper (char c);
abstract member ToUpper : char -> char
override this.ToUpper : char -> char
member this.ToUpper : char -> char
Public Overridable Function ToUpper (c As Char) As Char
Public Function ToUpper (c As Char) As Char

參數

c
Char

要轉換為大寫的字元。

傳回

轉換為大寫的指定字元。

備註

大小寫語意取決於使用中的文化特性。 對於不因文化特性而異的文化特性,大小寫語意不區分文化特性。 針對特定文化特性,大小寫語意會區分該文化特性。

如果安全性決策取決於字串比較或大小寫變更作業,應用程式應該使用 InvariantCulture 以確保不論系統的文化特性設定為何,行為都一致。 不過,非變異文化特性只能由需要與文化特性無關結果的進程使用,例如系統服務。 否則,它會產生語言不正確或文化上不適當的結果。

如需文化特性的詳細資訊,請參閱 CultureInfo

另請參閱

適用於

ToUpper(String)

來源:
TextInfo.cs
來源:
TextInfo.cs
來源:
TextInfo.cs

將指定字串轉換為大寫。

public:
 virtual System::String ^ ToUpper(System::String ^ str);
public:
 System::String ^ ToUpper(System::String ^ str);
public virtual string ToUpper (string str);
public string ToUpper (string str);
abstract member ToUpper : string -> string
override this.ToUpper : string -> string
member this.ToUpper : string -> string
Public Overridable Function ToUpper (str As String) As String
Public Function ToUpper (str As String) As String

參數

str
String

要轉換為大寫的字串。

傳回

轉換為大寫的指定字串。

例外狀況

str 為 null。

備註

傳回的字串長度可能與輸入字串不同。 如需大小寫的詳細資訊,請參閱 Unicode 聯盟所發佈的 Unicode 技術報告 #21「案例對應」 (https://www.unicode.org) 。 目前的實作會保留字串的長度。 不過,此行為不保證,未來實作可能會變更。

大小寫語意取決於使用中的文化特性。 對於不因文化特性而異的文化特性,大小寫語意不區分文化特性。 針對特定文化特性,大小寫語意會區分該文化特性。

如果安全性決策取決於字串比較或大小寫變更作業,應用程式應該使用 InvariantCulture 以確保不論系統的文化特性設定為何,行為都一致。 不過,非變異文化特性只能由需要與文化特性無關結果的進程使用,例如系統服務。 否則,它會產生語言不正確或文化上不適當的結果。

如需文化特性的詳細資訊,請參閱 CultureInfo

另請參閱

適用於