CharUnicodeInfo.GetUnicodeCategory 메서드

정의

유니코드 문자의 유니코드 범주를 가져옵니다.

오버로드

GetUnicodeCategory(Char)

지정된 문자의 유니코드 범주를 가져옵니다.

GetUnicodeCategory(Int32)

지정된 문자의 유니코드 범주를 가져옵니다.

GetUnicodeCategory(String, Int32)

지정된 문자열의 지정된 인덱스에 있는 문자의 유니코드 범주를 가져옵니다.

GetUnicodeCategory(Char)

지정된 문자의 유니코드 범주를 가져옵니다.

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

매개 변수

ch
Char

유니코드 범주를 가져올 유니코드 문자입니다.

반환

UnicodeCategory

지정된 문자의 범주를 나타내는 UnicodeCategory 값입니다.

예제

다음 코드 예제에서는 각 메서드에서 서로 다른 형식의 문자에 대해 반환된 값을 보여 있습니다.

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

설명

유니코드 문자는 범주로 구분됩니다. 문자의 범주는 해당 속성 중 하나입니다. 예를 들어 문자는 대문자, 소문자, 10진수 숫자, 문자 번호, 커넥터 문장 부호, 수학 기호 또는 통화 기호일 수 있습니다. 클래스는 UnicodeCategory 유니코드 문자의 범주를 반환합니다. 유니코드 문자에 대한 자세한 내용은 유니코드 표준을 참조하세요.

메서드는 GetUnicodeCategory 단일 언어 문자에 해당하고 해당 ch 범주를 반환한다고 가정합니다. 즉, 서로게이트 쌍의 경우 서로게이트가 속한 범주 대신 반환 UnicodeCategory.Surrogate 됩니다. 예를 들어 Ugaritic 알파벳은 U+10380에서 U+1039F까지의 코드 포인트를 차지합니다. 다음 예제에서는 이 메서드를 사용하여 ConvertFromUtf32 UGARITIC LETTER ALPA(U+10380)를 나타내는 문자열을 인스턴스화합니다. 이 문자열은 Ugaritic 알파벳의 첫 번째 문자입니다. 예제의 출력에서 보여 주듯이 메서드 IsNumber(Char) 는 이 문자의 상위 서로게이트 또는 하위 서로게이트를 전달하는 경우 반환 false 합니다.

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

CharUnicodeInfo.GetUnicodeCategory 특정 문자를 매개 변수로 전달할 때 메서드와 Char.GetUnicodeCategory 동일한 UnicodeCategory 값을 항상 반환하지는 않습니다. 이 CharUnicodeInfo.GetUnicodeCategory 메서드는 유니코드 표준의 현재 버전을 반영하도록 설계되었습니다. 반면, 메서드는 Char.GetUnicodeCategory 일반적으로 유니코드 표준의 현재 버전을 반영하지만 이전 버전의 표준에 따라 문자의 범주를 반환하거나 이전 버전과의 호환성을 유지하기 위해 현재 표준과 다른 범주를 반환할 수 있습니다.

추가 정보

적용 대상

GetUnicodeCategory(Int32)

지정된 문자의 유니코드 범주를 가져옵니다.

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

매개 변수

codePoint
Int32

유니코드 문자의 32비트 코드 포인트 값을 나타내는 숫자입니다.

반환

UnicodeCategory

지정된 문자의 범주를 나타내는 UnicodeCategory 값입니다.

적용 대상

GetUnicodeCategory(String, Int32)

지정된 문자열의 지정된 인덱스에 있는 문자의 유니코드 범주를 가져옵니다.

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

매개 변수

s
String

유니코드 범주를 가져올 유니코드 문자가 들어 있는 String입니다.

index
Int32

유니코드 범주를 가져올 유니코드 문자의 인덱스입니다.

반환

UnicodeCategory

지정된 문자열의 지정된 인덱스에 있는 문자의 범주를 나타내는 UnicodeCategory 값입니다.

예외

s이(가) null인 경우

indexs의 올바른 인덱스 범위 밖에 있는 경우

예제

다음 코드 예제에서는 각 메서드에서 서로 다른 형식의 문자에 대해 반환된 값을 보여 있습니다.

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

설명

유니코드 문자는 범주로 구분됩니다. 문자의 범주는 해당 속성 중 하나입니다. 예를 들어 문자는 대문자, 소문자, 10진수 숫자, 문자 번호, 커넥터 문장 부호, 수학 기호 또는 통화 기호일 수 있습니다. 클래스는 UnicodeCategory 유니코드 문자의 범주를 반환합니다. 유니코드 문자에 대한 자세한 내용은 유니코드 표준을 참조하세요.

위치에 있는 Char 개체가 유효한 서로게이트 쌍 GetUnicodeCategory(String, Int32) 의 첫 번째 문자인 경우 메서드는 반환하는 대신 서로게이트 쌍의 유니코드 범주를 반환합니다UnicodeCategory.Surrogate.index 예를 들어 Ugaritic 알파벳은 U+10380에서 U+1039F까지의 코드 포인트를 차지합니다. 다음 예제에서는 이 메서드를 사용하여 ConvertFromUtf32 UGARITIC LETTER ALPA(U+10380)를 나타내는 문자열을 인스턴스화합니다. 이 문자열은 Ugaritic 알파벳의 첫 번째 문자입니다. 예제의 출력에서 보 GetUnicodeCategory(String, Int32) 듯이 메서드는 서로게이트 쌍을 고려한다는 것을 나타내는 이 문자의 상위 서로게이트를 전달하면 반환 UnicodeCategory.OtherLetter 됩니다. 그러나 하위 서로게이트를 전달하는 경우 격리된 하위 서로게이트만 고려하고 반환합니다 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

CharUnicodeInfo.GetUnicodeCategory 특정 문자를 매개 변수로 전달할 때 메서드가 Char.GetUnicodeCategory 항상 메서드와 동일한 UnicodeCategory 값을 반환하지는 않습니다. 이 CharUnicodeInfo.GetUnicodeCategory 메서드는 유니코드 표준의 현재 버전을 반영하도록 설계되었습니다. 반면, 메서드는 Char.GetUnicodeCategory 일반적으로 유니코드 표준의 현재 버전을 반영하지만 이전 버전의 표준에 따라 문자의 범주를 반환하거나 이전 버전과의 호환성을 유지하기 위해 현재 표준과 다른 범주를 반환할 수 있습니다.

추가 정보

적용 대상