CharUnicodeInfo.GetUnicodeCategory Método

Definição

Obtém a categoria Unicode de um carácter Unicode.

Sobrecargas

Name Description
GetUnicodeCategory(Char)

Obtém a categoria Unicode do carácter especificado.

GetUnicodeCategory(Int32)

Obtém a categoria Unicode do carácter especificado.

GetUnicodeCategory(String, Int32)

Obtém a categoria Unicode do carácter no índice especificado da cadeia especificada.

GetUnicodeCategory(Char)

Obtém a categoria Unicode do carácter especificado.

public:
 static System::Globalization::UnicodeCategory GetUnicodeCategory(char ch);
public static System.Globalization.UnicodeCategory GetUnicodeCategory(char ch);
static member GetUnicodeCategory : char -> System.Globalization.UnicodeCategory
Public Shared Function GetUnicodeCategory (ch As Char) As UnicodeCategory

Parâmetros

ch
Char

O carácter Unicode para obter a categoria Unicode.

Devoluções

Um valor que UnicodeCategory indica a categoria do carácter especificado.

Exemplos

O exemplo de código seguinte mostra os valores devolvidos por cada método para diferentes tipos de caracteres.

using System;
using System.Globalization;

public class SamplesCharUnicodeInfo  {

   public static void Main()  {

      Console.WriteLine( "                                        c  Num   Dig   Dec   UnicodeCategory" );

      Console.Write( "U+0061 LATIN SMALL LETTER A            " );
      PrintProperties( 'a' );

      Console.Write( "U+0393 GREEK CAPITAL LETTER GAMMA      " );
      PrintProperties( '\u0393' );

      Console.Write( "U+0039 DIGIT NINE                      " );
      PrintProperties( '9' );

      Console.Write( "U+00B2 SUPERSCRIPT TWO                 " );
      PrintProperties( '\u00B2' );

      Console.Write( "U+00BC VULGAR FRACTION ONE QUARTER     " );
      PrintProperties( '\u00BC' );

      Console.Write( "U+0BEF TAMIL DIGIT NINE                " );
      PrintProperties( '\u0BEF' );

      Console.Write( "U+0BF0 TAMIL NUMBER TEN                " );
      PrintProperties( '\u0BF0' );

      Console.Write( "U+0F33 TIBETAN DIGIT HALF ZERO         " );
      PrintProperties( '\u0F33' );

      Console.Write( "U+2788 CIRCLED SANS-SERIF DIGIT NINE   " );
      PrintProperties( '\u2788' );
   }

   public static void PrintProperties( char c )  {
      Console.Write( " {0,-3}", c );
      Console.Write( " {0,-5}", CharUnicodeInfo.GetNumericValue( c ) );
      Console.Write( " {0,-5}", CharUnicodeInfo.GetDigitValue( c ) );
      Console.Write( " {0,-5}", CharUnicodeInfo.GetDecimalDigitValue( c ) );
      Console.WriteLine( "{0}", CharUnicodeInfo.GetUnicodeCategory( c ) );
   }
}


/*
This code produces the following output.  Some characters might not display at the console.

                                        c  Num   Dig   Dec   UnicodeCategory
U+0061 LATIN SMALL LETTER A             a   -1    -1    -1   LowercaseLetter
U+0393 GREEK CAPITAL LETTER GAMMA       Γ   -1    -1    -1   UppercaseLetter
U+0039 DIGIT NINE                       9   9     9     9    DecimalDigitNumber
U+00B2 SUPERSCRIPT TWO                  ²   2     2     -1   OtherNumber
U+00BC VULGAR FRACTION ONE QUARTER      ¼   0.25  -1    -1   OtherNumber
U+0BEF TAMIL DIGIT NINE                 ௯   9     9     9    DecimalDigitNumber
U+0BF0 TAMIL NUMBER TEN                 ௰   10    -1    -1   OtherNumber
U+0F33 TIBETAN DIGIT HALF ZERO          ༳   -0.5  -1    -1   OtherNumber
U+2788 CIRCLED SANS-SERIF DIGIT NINE    ➈   9     9     -1   OtherNumber

*/
Imports System.Globalization

Public Class SamplesCharUnicodeInfo

   Public Shared Sub Main()

      Console.WriteLine("                                        c  Num   Dig   Dec   UnicodeCategory")

      Console.Write("U+0061 LATIN SMALL LETTER A            ")
      PrintProperties("a"c)

      Console.Write("U+0393 GREEK CAPITAL LETTER GAMMA      ")
      PrintProperties(ChrW(&H0393))

      Console.Write("U+0039 DIGIT NINE                      ")
      PrintProperties("9"c)

      Console.Write("U+00B2 SUPERSCRIPT TWO                 ")
      PrintProperties(ChrW(&H00B2))

      Console.Write("U+00BC VULGAR FRACTION ONE QUARTER     ")
      PrintProperties(ChrW(&H00BC))

      Console.Write("U+0BEF TAMIL DIGIT NINE                ")
      PrintProperties(ChrW(&H0BEF))

      Console.Write("U+0BF0 TAMIL NUMBER TEN                ")
      PrintProperties(ChrW(&H0BF0))

      Console.Write("U+0F33 TIBETAN DIGIT HALF ZERO         ")
      PrintProperties(ChrW(&H0F33))

      Console.Write("U+2788 CIRCLED SANS-SERIF DIGIT NINE   ")
      PrintProperties(ChrW(&H2788))

   End Sub

   Public Shared Sub PrintProperties(c As Char)
      Console.Write(" {0,-3}", c)
      Console.Write(" {0,-5}", CharUnicodeInfo.GetNumericValue(c))
      Console.Write(" {0,-5}", CharUnicodeInfo.GetDigitValue(c))
      Console.Write(" {0,-5}", CharUnicodeInfo.GetDecimalDigitValue(c))
      Console.WriteLine("{0}", CharUnicodeInfo.GetUnicodeCategory(c))
   End Sub

End Class


'This code produces the following output.  Some characters might not display at the console.
'
'                                        c  Num   Dig   Dec   UnicodeCategory
'U+0061 LATIN SMALL LETTER A             a   -1    -1    -1   LowercaseLetter
'U+0393 GREEK CAPITAL LETTER GAMMA       Γ   -1    -1    -1   UppercaseLetter
'U+0039 DIGIT NINE                       9   9     9     9    DecimalDigitNumber
'U+00B2 SUPERSCRIPT TWO                  ²   2     2     -1   OtherNumber
'U+00BC VULGAR FRACTION ONE QUARTER      ¼   0.25  -1    -1   OtherNumber
'U+0BEF TAMIL DIGIT NINE                 ௯   9     9     9    DecimalDigitNumber
'U+0BF0 TAMIL NUMBER TEN                 ௰   10    -1    -1   OtherNumber
'U+0F33 TIBETAN DIGIT HALF ZERO          ༳   -0.5  -1    -1   OtherNumber
'U+2788 CIRCLED SANS-SERIF DIGIT NINE    ➈   9     9     -1   OtherNumber

Observações

Os caracteres Unicode estão divididos em categorias. A categoria de uma personagem é uma das suas propriedades. Por exemplo, um carácter pode ser uma letra maiúscula, uma letra minúscula, um número decimal, um número de letra, uma pontuação de conector, um símbolo matemático ou um símbolo de moeda. A UnicodeCategory enumeração define a categoria de um carácter Unicode. Para mais informações sobre caracteres Unicode, consulte o Padrão Unicode.

O GetUnicodeCategory método assume que ch corresponde a um único carácter linguístico e devolve a sua categoria. Isto significa que, para pares de substitutos, ele retorna UnicodeCategory.Surrogate em vez da categoria a que o substituto pertence. Por exemplo, o alfabeto ugarítico ocupa os pontos de código U+10380 a U+1039F. O exemplo seguinte utiliza o ConvertFromUtf32 método para instanciar uma cadeia que representa a LETRA UGARÍTICA ALPA (U+10380), que é a primeira letra do alfabeto Ugarítico. Como mostra a saída do exemplo, o IsNumber(Char) método devolve false se for passado o substituto alto ou o substituto baixo deste carácter.

int utf32 = 0x10380;       // UGARITIC LETTER ALPA
string surrogate = Char.ConvertFromUtf32(utf32);
foreach (var ch in surrogate)
    Console.WriteLine($"U+{(ushort)ch:X4}: {System.Globalization.CharUnicodeInfo.GetUnicodeCategory(ch):G}");
// The example displays the following output:
//       U+D800: Surrogate
//       U+DF80: Surrogate
Dim utf32 As Integer = &h10380       ' UGARITIC LETTER ALPA
Dim surrogate As String = Char.ConvertFromUtf32(utf32)
For Each ch In surrogate
   Console.WriteLine("U+{0:X4}: {1:G}", 
                     Convert.ToUInt16(ch), 
                     System.Globalization.CharUnicodeInfo.GetUnicodeCategory(ch))
Next
' The example displays the following output:
'       U+D800: Surrogate
'       U+DF80: Surrogate

Note que CharUnicodeInfo.GetUnicodeCategory nem sempre devolve o mesmo UnicodeCategory valor do Char.GetUnicodeCategory método quando é passado um determinado carácter como parâmetro. O CharUnicodeInfo.GetUnicodeCategory método foi concebido para refletir a versão atual do padrão Unicode. Em contraste, embora o Char.GetUnicodeCategory método normalmente reflita a versão atual do padrão Unicode, pode devolver a categoria de um carácter com base numa versão anterior do padrão, ou pode devolver uma categoria que difere do padrão atual para preservar a compatibilidade retroativa.

Ver também

Aplica-se a

GetUnicodeCategory(Int32)

Obtém a categoria Unicode do carácter especificado.

public:
 static System::Globalization::UnicodeCategory GetUnicodeCategory(int codePoint);
public static System.Globalization.UnicodeCategory GetUnicodeCategory(int codePoint);
static member GetUnicodeCategory : int -> System.Globalization.UnicodeCategory
Public Shared Function GetUnicodeCategory (codePoint As Integer) As UnicodeCategory

Parâmetros

codePoint
Int32

Um número que representa o valor do ponto de código de 32 bits do carácter Unicode.

Devoluções

Um valor que UnicodeCategory indica a categoria do carácter especificado.

Aplica-se a

GetUnicodeCategory(String, Int32)

Obtém a categoria Unicode do carácter no índice especificado da cadeia especificada.

public:
 static System::Globalization::UnicodeCategory GetUnicodeCategory(System::String ^ s, int index);
public static System.Globalization.UnicodeCategory GetUnicodeCategory(string s, int index);
static member GetUnicodeCategory : string * int -> System.Globalization.UnicodeCategory
Public Shared Function GetUnicodeCategory (s As String, index As Integer) As UnicodeCategory

Parâmetros

s
String

O String que contém o carácter Unicode para o qual se obtém a categoria Unicode.

index
Int32

O índice do carácter Unicode para o qual obter a categoria Unicode.

Devoluções

Um valor que UnicodeCategory indica a categoria do carácter no índice especificado da cadeia especificada.

Exceções

index está fora do intervalo dos índices válidos em s.

Exemplos

O exemplo de código seguinte mostra os valores devolvidos por cada método para diferentes tipos de caracteres.

using System;
using System.Globalization;

public class SamplesCharUnicodeInfo  {

   public static void Main()  {

      // The String to get information for.
      String s = "a9\u0393\u00B2\u00BC\u0BEF\u0BF0\u2788";
      Console.WriteLine( "String: {0}", s );

      // Print the values for each of the characters in the string.
      Console.WriteLine( "index c  Num   Dig   Dec   UnicodeCategory" );
      for ( int i = 0; i < s.Length; i++ )  {
         Console.Write( "{0,-5} {1,-3}", i, s[i] );
         Console.Write( " {0,-5}", CharUnicodeInfo.GetNumericValue( s, i ) );
         Console.Write( " {0,-5}", CharUnicodeInfo.GetDigitValue( s, i ) );
         Console.Write( " {0,-5}", CharUnicodeInfo.GetDecimalDigitValue( s, i ) );
         Console.WriteLine( "{0}", CharUnicodeInfo.GetUnicodeCategory( s, i ) );
      }
   }
}


/*
This code produces the following output.  Some characters might not display at the console.

String: a9Γ²¼௯௰➈
index c  Num   Dig   Dec   UnicodeCategory
0     a   -1    -1    -1   LowercaseLetter
1     9   9     9     9    DecimalDigitNumber
2     Γ   -1    -1    -1   UppercaseLetter
3     ²   2     2     -1   OtherNumber
4     ¼   0.25  -1    -1   OtherNumber
5     ௯   9     9     9    DecimalDigitNumber
6     ௰   10    -1    -1   OtherNumber
7     ➈   9     9     -1   OtherNumber

*/
Imports System.Globalization

Public Class SamplesCharUnicodeInfo

   Public Shared Sub Main()

      ' The String to get information for.
      Dim s As [String] = "a9\u0393\u00B2\u00BC\u0BEF\u0BF0\u2788"
      Console.WriteLine("String: {0}", s)

      ' Print the values for each of the characters in the string.
      Console.WriteLine("index c  Num   Dig   Dec   UnicodeCategory")
      Dim i As Integer
      For i = 0 To s.Length - 1
         Console.Write("{0,-5} {1,-3}", i, s(i))
         Console.Write(" {0,-5}", CharUnicodeInfo.GetNumericValue(s, i))
         Console.Write(" {0,-5}", CharUnicodeInfo.GetDigitValue(s, i))
         Console.Write(" {0,-5}", CharUnicodeInfo.GetDecimalDigitValue(s, i))
         Console.WriteLine("{0}", CharUnicodeInfo.GetUnicodeCategory(s, i))
      Next i

   End Sub

End Class


'This code produces the following output.  Some characters might not display at the console.
'
'String: a9Γ²¼௯௰➈
'index c  Num   Dig   Dec   UnicodeCategory
'0     a   -1    -1    -1   LowercaseLetter
'1     9   9     9     9    DecimalDigitNumber
'2     Γ   -1    -1    -1   UppercaseLetter
'3     ²   2     2     -1   OtherNumber
'4     ¼   0.25  -1    -1   OtherNumber
'5     ௯   9     9     9    DecimalDigitNumber
'6     ௰   10    -1    -1   OtherNumber
'7     ➈   9     9     -1   OtherNumber

Observações

Os caracteres Unicode estão divididos em categorias. A categoria de uma personagem é uma das suas propriedades. Por exemplo, um carácter pode ser uma letra maiúscula, uma letra minúscula, um número decimal, um número de letra, uma pontuação de conector, um símbolo matemático ou um símbolo de moeda. A UnicodeCategory enumeração define a categoria de um carácter Unicode. Para mais informações sobre caracteres Unicode, consulte o Padrão Unicode.

Se o Char objeto na posição index for o primeiro carácter de um par substituto válido, o GetUnicodeCategory(String, Int32) método devolve a categoria Unicode do par substituto em vez de devolver UnicodeCategory.Surrogate. Por exemplo, o alfabeto ugarítico ocupa os pontos de código U+10380 a U+1039F. O exemplo seguinte utiliza o ConvertFromUtf32 método para instanciar uma cadeia que representa a LETRA UGARÍTICA ALPA (U+10380), que é a primeira letra do alfabeto Ugarítico. Como a saída do exemplo mostra, o GetUnicodeCategory(String, Int32) método devolve UnicodeCategory.OtherLetter se for ultrapassado o substituto alto deste carácter, o que indica que considera o par substituto. No entanto, se for ultrapassado o substituto baixo, considera apenas o substituto baixo isoladamente e retorna UnicodeCategory.Surrogate.

int utf32 = 0x10380;       // UGARITIC LETTER ALPA
string surrogate = Char.ConvertFromUtf32(utf32);
for (int ctr = 0; ctr < surrogate.Length; ctr++)
    Console.WriteLine($"U+{(ushort)surrogate[ctr]:X4}: {System.Globalization.CharUnicodeInfo.GetUnicodeCategory(surrogate, ctr):G}");
// The example displays the following output:
//       U+D800: OtherLetter
//       U+DF80: Surrogate
Dim utf32 As Integer = &h10380       ' UGARITIC LETTER ALPA
Dim surrogate As String = Char.ConvertFromUtf32(utf32)
For ctr As Integer = 0 To surrogate.Length - 1
   Console.WriteLine("U+{0:X4}: {1:G}", 
                     Convert.ToUInt16(surrogate(ctr)), 
                     System.Globalization.CharUnicodeInfo.GetUnicodeCategory(surrogate, ctr))
Next
' The example displays the following output:
'       U+D800: OtherLetter
'       U+DF80: Surrogate

Note-se que CharUnicodeInfo.GetUnicodeCategory o método nem sempre devolve o mesmo UnicodeCategory valor que o Char.GetUnicodeCategory método quando é passado um determinado carácter como parâmetro. O CharUnicodeInfo.GetUnicodeCategory método foi concebido para refletir a versão atual do padrão Unicode. Em contraste, embora o Char.GetUnicodeCategory método normalmente reflita a versão atual do padrão Unicode, pode devolver a categoria de um carácter com base numa versão anterior do padrão, ou pode devolver uma categoria que difere do padrão atual para preservar a compatibilidade retroativa.

Ver também

Aplica-se a