Char.ToUpper 方法
定義
將 Unicode 字元值轉換成它的對等大寫。Converts the value of a Unicode character to its uppercase equivalent.
多載
ToUpper(Char, CultureInfo) |
使用指定的特定文化特性格式資訊,將指定的 Unicode 字元值轉換成它的對等大寫。Converts the value of a specified Unicode character to its uppercase equivalent using specified culture-specific formatting information. |
ToUpper(Char) |
將 Unicode 字元值轉換成它的對等大寫。Converts the value of a Unicode character to its uppercase equivalent. |
ToUpper(Char, CultureInfo)
使用指定的特定文化特性格式資訊,將指定的 Unicode 字元值轉換成它的對等大寫。Converts the value of a specified Unicode character to its uppercase equivalent using specified culture-specific formatting information.
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 字元。The Unicode character to convert.
- culture
- CultureInfo
提供文化特性大小寫規則的物件。An object that supplies culture-specific casing rules.
傳回
c
的對等大寫 (已根據 culture
修改);如果 c
已經是大寫、沒有對等大寫或不是英文字母,則為未變更的 c
值。The uppercase equivalent of c
, modified according to culture
, or the unchanged value of c
if c
is already uppercase, has no uppercase equivalent, or is not alphabetic.
例外狀況
culture
為 null
。culture
is null
.
範例
下列範例會將陣列中的每個字元轉換為 en-us 文化特性的大寫相等、不因文化特性而異,以及 tr-TR 文化特性。The following example converts each character in an array to its uppercase equivalent for the en-US culture, the invariant culture, and the tr-TR culture. 在此範例中,所有文化特性的大寫等同于所有文化特性,但一種情況除外。In this example, the uppercase equivalent of each lowercase letter is identical for all cultures except for one case. 小寫 "i" 字元 (U + 0069) 會將 en-us 和非變異文化特性中的 "I" (U + 0049) 轉換為 "i",但在 tr 的文化特性中則會轉換為 "i" (U + 0130) 。The lowercase "i" character (U+0069) converts to "I" (U+0049) in the en-US and invariant cultures, but to "İ" (U+0130) in the tr-TR culture.
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
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 來將字串轉換成大寫。Use String.ToUpper to convert a string to uppercase.
另請參閱
- ToUpper(Rune, CultureInfo)
- ToLower(Rune, CultureInfo)
- CurrentCulture
- ToUpper()
- ToLower(Char, CultureInfo)
適用於
ToUpper(Char)
將 Unicode 字元值轉換成它的對等大寫。Converts the value of a Unicode character to its uppercase equivalent.
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 字元。The Unicode character to convert.
傳回
c
的對等大寫;如果 c
已經是大寫、沒有對等大寫或不是英文字母,則為未變更的 c
值。The uppercase equivalent of c
, or the unchanged value of c
if c
is already uppercase, has no uppercase equivalent, or is not alphabetic.
範例
下列範例會將陣列中的每個字元轉換成它的對等大寫。The following example converts each character in an array to its uppercase equivalent.
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)
// ? --> ?
// ä --> Ä
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)
' ж --> Ж
' ä --> Ä
備註
大小寫規則是從目前的文化特性取得。Casing rules are obtained from the current culture.
用 String.ToUpper 來將字串轉換成大寫。Use String.ToUpper to convert a string to uppercase.
給呼叫者的注意事項
如 使用字串的最佳做法中所述,我們建議您避免呼叫替代預設值的字元大小寫和字串大小寫方法。As explained in Best Practices for Using Strings, we recommend that you avoid calling character-casing and string-casing methods that substitute default values. 相反地,您應該呼叫需要明確指定參數的方法。Instead, you should call methods that require parameters to be explicitly specified. 若要使用目前文化特性的大小寫慣例,將字元轉換成大寫,請使用的值來呼叫方法多載,以做 ToUpper(Char, CultureInfo) CurrentCulture 為其參數的值 culture
。To convert a character to uppercase by using the casing conventions of the current culture, call the ToUpper(Char, CultureInfo) method overload with a value of CurrentCulture for its culture
parameter.