Char.ToUpper 方法

定義

將 Unicode 字元值轉換成它的對等大寫。

多載

ToUpper(Char, CultureInfo)

使用指定的特定文化特性格式資訊,將指定的 Unicode 字元值轉換成它的對等大寫。

ToUpper(Char)

將 Unicode 字元值轉換成它的對等大寫。

ToUpper(Char, CultureInfo)

使用指定的特定文化特性格式資訊,將指定的 Unicode 字元值轉換成它的對等大寫。

public:
 static char ToUpper(char c, System::Globalization::CultureInfo ^ culture);
public static char ToUpper (char c, System.Globalization.CultureInfo culture);
static member ToUpper : char * System.Globalization.CultureInfo -> char
Public Shared Function ToUpper (c As Char, culture As CultureInfo) As Char

參數

c
Char

要轉換的 Unicode 字元。

culture
CultureInfo

提供文化特性大小寫規則的物件。

傳回

Char

c 的對等大寫 (已根據 culture 修改);如果 c 已經是大寫、沒有對等大寫或不是英文字母,則為未變更的 c 值。

例外狀況

culturenull

範例

下列範例會將陣列中的每個字元轉換為 en-us 文化特性的大寫相等、不因文化特性而異,以及 tr-TR 文化特性。 在此範例中,所有文化特性的大寫等同于所有文化特性,但一種情況除外。 小寫 "i" 字元 (U + 0069) 會將 en-us 和非變異文化特性中的 "I" (U + 0049) 轉換為 "i",但在 tr 的文化特性中則會轉換為 "i" (U + 0130) 。

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CultureInfo[] cultures= { CultureInfo.CreateSpecificCulture("en-US"),
                                CultureInfo.InvariantCulture,
                                CultureInfo.CreateSpecificCulture("tr-TR") };
      Char[] chars = {'ä', 'e', 'E', 'i', 'I' };

      Console.WriteLine("Character     en-US     Invariant     tr-TR");
      foreach (var ch in chars) {
         Console.Write("    {0}", ch);
         foreach (var culture in cultures)
            Console.Write("{0,12}", Char.ToUpper(ch, culture));

         Console.WriteLine();
      }
   }
}
// The example displays the following output:
//       Character     en-US     Invariant     tr-TR
//           ä           Ä           Ä           Ä
//           e           E           E           E
//           E           E           E           E
//           i           I           I           İ
//           I           I           I           I
open System
open System.Globalization

let cultures= 
    [ CultureInfo.CreateSpecificCulture "en-US"
      CultureInfo.InvariantCulture
      CultureInfo.CreateSpecificCulture "tr-TR" ]

let chars = [| 'ä'; 'e'; 'E'; 'i'; 'I' |]

printfn "Character     en-US     Invariant     tr-TR"
for ch in chars do
    printf $"    {ch}"
    for culture in cultures do
        printf $"{Char.ToUpper(ch, culture),12}"
    printfn ""


// The example displays the following output:
//       Character     en-US     Invariant     tr-TR
//           ä           Ä           Ä           Ä
//           e           E           E           E
//           E           E           E           E
//           i           I           I           İ
//           I           I           I           I
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim cultures() As CultureInfo = { CultureInfo.CreateSpecificCulture("en-US"), 
                                        CultureInfo.InvariantCulture, 
                                        CultureInfo.CreateSpecificCulture("tr-TR") }
      Dim chars() As Char = {"ä"c, "e"c, "E"c, "i"c, "I"c }

      Console.WriteLine("Character     en-US     Invariant     tr-TR")
      For Each ch In chars
         Console.Write("    {0}", ch)
         For Each culture In cultures
            Console.Write("{0,12}", Char.ToUpper(ch, culture))
         Next
         Console.WriteLine()
      Next   
   End Sub
End Module
' The example displays the following output:
'       Character     en-US     Invariant     tr-TR
'           ä           Ä           Ä           Ä
'           e           E           E           E
'           E           E           E           E
'           i           I           I           İ
'           I           I           I           I

備註

String.ToUpper 來將字串轉換成大寫。

另請參閱

適用於

ToUpper(Char)

將 Unicode 字元值轉換成它的對等大寫。

public:
 static char ToUpper(char c);
public static char ToUpper (char c);
static member ToUpper : char -> char
Public Shared Function ToUpper (c As Char) As Char

參數

c
Char

要轉換的 Unicode 字元。

傳回

Char

c 的對等大寫;如果 c 已經是大寫、沒有對等大寫或不是英文字母,則為未變更的 c 值。

範例

下列範例會將陣列中的每個字元轉換成它的對等大寫。

using System;

public class Example
{
   public static void Main()
   {
      char[] chars = { 'e', 'E', '6', ',', 'ж', 'ä' };
      foreach (var ch in chars)
          Console.WriteLine("{0} --> {1} {2}", ch, Char.ToUpper(ch),
                            ch == Char.ToUpper(ch) ? "(Same Character)" : "" );
   }
}
// The example displays the following output:
//       e --> E
//       E --> E (Same Character)
//       6 --> 6 (Same Character)
//       , --> , (Same Character)
//       ж --> Ж
//       ä --> Ä
open System

let chars = [| 'e'; 'E'; '6'; ','; 'ж'; 'ä' |]

for ch in chars do
    printfn $"""{ch} --> {Char.ToUpper ch} {if ch = Char.ToUpper ch then "(Same Character)" else ""}"""

// The example displays the following output:
//       e --> E
//       E --> E (Same Character)
//       6 --> 6 (Same Character)
//       , --> , (Same Character)
//       ж --> Ж
//       ä --> Ä
Module Example
   Public Sub Main()
      Dim chars() As Char = { "e"c, "E"c, "6"c, ","c, "ж"c, "ä"c }
      For Each ch In chars
         Console.WriteLine("{0} --> {1} {2}", ch, Char.ToUpper(ch),
                           If(ch = Char.ToUpper(ch), "(Same Character)", ""))
      Next
   End Sub
End Module
' The example displays the following output:
'       e --> E
'       E --> E (Same Character)
'       6 --> 6 (Same Character)
'       , --> , (Same Character)
'       ж --> Ж
'       ä --> Ä

備註

大小寫規則是從目前的文化特性取得。

String.ToUpper 來將字串轉換成大寫。

給呼叫者的注意事項

使用字串的最佳做法中所述,我們建議您避免呼叫替代預設值的字元大小寫和字串大小寫方法。 相反地,您應該呼叫需要明確指定參數的方法。 若要使用目前文化特性的大小寫慣例,將字元轉換成大寫,請使用的值來呼叫方法多載,以做 ToUpper(Char, CultureInfo) CurrentCulture 為其參數的值 culture

另請參閱

適用於