CharUnicodeInfo.GetUnicodeCategory Método

Definición

Obtiene la categoría de Unicode de un carácter Unicode.

Sobrecargas

GetUnicodeCategory(Char)

Obtiene la categoría de Unicode del carácter especificado.

GetUnicodeCategory(Int32)

Obtiene la categoría de Unicode del carácter especificado.

GetUnicodeCategory(String, Int32)

Obtiene la categoría de Unicode del carácter situado en el índice especificado de la cadena especificada.

GetUnicodeCategory(Char)

Obtiene la categoría de Unicode del 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

El carácter Unicode para el que se obtiene la categoría de Unicode.

Devoluciones

UnicodeCategory

Un valor UnicodeCategory que indica la categoría del carácter especificado.

Ejemplos

En el ejemplo de código siguiente se muestran los valores devueltos por cada método para distintos tipos de caracteres.

using namespace System;
using namespace System::Globalization;
void PrintProperties( Char c );
int main()
{
   Console::WriteLine( "                                        c  Num   Dig   Dec   UnicodeCategory" );
   Console::Write( "U+0061 LATIN SMALL LETTER A            " );
   PrintProperties( L'a' );
   Console::Write( "U+0393 GREEK CAPITAL LETTER GAMMA      " );
   PrintProperties( L'\u0393' );
   Console::Write( "U+0039 DIGIT NINE                      " );
   PrintProperties( L'9' );
   Console::Write( "U+00B2 SUPERSCRIPT TWO                 " );
   PrintProperties( L'\u00B2' );
   Console::Write( "U+00BC VULGAR FRACTION ONE QUARTER     " );
   PrintProperties( L'\u00BC' );
   Console::Write( "U+0BEF TAMIL DIGIT NINE                " );
   PrintProperties( L'\u0BEF' );
   Console::Write( "U+0BF0 TAMIL NUMBER TEN                " );
   PrintProperties( L'\u0BF0' );
   Console::Write( "U+0F33 TIBETAN DIGIT HALF ZERO         " );
   PrintProperties( L'\u0F33' );
   Console::Write( "U+2788 CIRCLED SANS-SERIF DIGIT NINE   " );
   PrintProperties( L'\u2788' );
}

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

*/
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

Comentarios

Los caracteres Unicode se dividen en categorías. La categoría de un carácter es una de sus propiedades. Por ejemplo, un carácter puede ser una letra mayúscula, una letra minúscula, un número de dígito decimal, un número de letra, un signo de puntuación de conector, un símbolo matemático o un símbolo de moneda. La UnicodeCategory clase devuelve la categoría de un carácter Unicode. Para obtener más información sobre los caracteres Unicode, consulte El estándar Unicode.

El GetUnicodeCategory método supone que ch corresponde a un único carácter lingüístico y devuelve su categoría. Esto significa que, para los pares suplentes, devuelve UnicodeCategory.Surrogate en lugar de la categoría a la que pertenece el suplente. Por ejemplo, el alfabeto Ugarítico ocupa puntos de código U+10380 a U+1039F. En el ejemplo siguiente se usa el ConvertFromUtf32 método para crear una instancia de una cadena que representa alPA LETRA UGARITIC (U+10380), que es la primera letra del alfabeto Ugaritic. Como se muestra en la salida del ejemplo, el IsNumber(Char) método devuelve false si se pasa el suplente alto o el suplente bajo de este 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

Tenga en cuenta que no siempre devuelve el mismo UnicodeCategory valor que CharUnicodeInfo.GetUnicodeCategory el Char.GetUnicodeCategory método cuando se pasa un carácter determinado como parámetro. El CharUnicodeInfo.GetUnicodeCategory método está diseñado para reflejar la versión actual del estándar Unicode. Por el contrario, aunque el Char.GetUnicodeCategory método normalmente refleja la versión actual del estándar Unicode, podría devolver la categoría de un carácter en función de una versión anterior del estándar, o podría devolver una categoría que difiere del estándar actual para conservar la compatibilidad con versiones anteriores.

Consulte también

Se aplica a

GetUnicodeCategory(Int32)

Obtiene la categoría de Unicode del 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

Número que representa el valor de punto de código de 32 bits del carácter Unicode.

Devoluciones

UnicodeCategory

Un valor UnicodeCategory que indica la categoría del carácter especificado.

Se aplica a

GetUnicodeCategory(String, Int32)

Obtiene la categoría de Unicode del carácter situado en el índice especificado de la cadena 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

El objeto String que contiene el carácter Unicode para el que se obtiene la categoría de Unicode.

index
Int32

El índice del carácter Unicode para el que se obtiene la categoría de Unicode.

Devoluciones

UnicodeCategory

Un valor UnicodeCategory que indica la categoría del carácter situado en el índice especificado de la cadena especificada.

Excepciones

index se encuentra fuera del intervalo de índices válidos en s.

Ejemplos

En el ejemplo de código siguiente se muestran los valores devueltos por cada método para distintos tipos de caracteres.

using namespace System;
using namespace System::Globalization;
int 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

*/
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

Comentarios

Los caracteres Unicode se dividen en categorías. La categoría de un carácter es una de sus propiedades. Por ejemplo, un carácter puede ser una letra mayúscula, una letra minúscula, un número de dígito decimal, un número de letra, un signo de puntuación de conector, un símbolo matemático o un símbolo de moneda. La UnicodeCategory clase devuelve la categoría de un carácter Unicode. Para obtener más información sobre los caracteres Unicode, consulte El estándar Unicode.

Si el Char objeto en posición index es el primer carácter de un par suplente válido, el GetUnicodeCategory(String, Int32) método devuelve la categoría Unicode del par suplente en lugar de devolver UnicodeCategory.Surrogate. Por ejemplo, el alfabeto Ugarítico ocupa puntos de código U+10380 a U+1039F. En el ejemplo siguiente se usa el ConvertFromUtf32 método para crear una instancia de una cadena que representa alPA LETRA UGARITIC (U+10380), que es la primera letra del alfabeto Ugaritic. Como se muestra en la salida del ejemplo, el GetUnicodeCategory(String, Int32) método devuelve UnicodeCategory.OtherLetter si se pasa el suplente alto de este carácter, lo que indica que considera el par suplente. Sin embargo, si se pasa el suplente bajo, solo tiene en cuenta el suplente bajo en aislamiento y devuelve 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

Tenga en cuenta que CharUnicodeInfo.GetUnicodeCategory el método no siempre devuelve el mismo UnicodeCategory valor que el Char.GetUnicodeCategory método cuando se pasa un carácter determinado como parámetro. El CharUnicodeInfo.GetUnicodeCategory método está diseñado para reflejar la versión actual del estándar Unicode. Por el contrario, aunque el Char.GetUnicodeCategory método normalmente refleja la versión actual del estándar Unicode, podría devolver la categoría de un carácter en función de una versión anterior del estándar, o podría devolver una categoría que difiere del estándar actual para conservar la compatibilidad con versiones anteriores.

Consulte también

Se aplica a