Muokkaa

Jaa


Char.ToUpper Method

Definition

Converts the value of a Unicode character to its uppercase equivalent.

Overloads

ToUpper(Char, CultureInfo)

Converts the value of a specified Unicode character to its uppercase equivalent using specified culture-specific formatting information.

ToUpper(Char)

Converts the value of a Unicode character to its uppercase equivalent.

ToUpper(Char, CultureInfo)

Source:
Char.cs
Source:
Char.cs
Source:
Char.cs

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

Parameters

c
Char

The Unicode character to convert.

culture
CultureInfo

An object that supplies culture-specific casing rules.

Returns

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.

Exceptions

culture is null.

Examples

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. 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
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

Remarks

Use String.ToUpper to convert a string to uppercase.

See also

Applies to

ToUpper(Char)

Source:
Char.cs
Source:
Char.cs
Source:
Char.cs

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

Parameters

c
Char

The Unicode character to convert.

Returns

The uppercase equivalent of c, or the unchanged value of c if c is already uppercase, has no uppercase equivalent, or is not alphabetic.

Examples

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)
//       ж --> Ж
//       ä --> Ä
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)
'       ж --> Ж
'       ä --> Ä

Remarks

Casing rules are obtained from the current culture.

Use String.ToUpper to convert a string to uppercase.

Notes to Callers

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. 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.

See also

Applies to