다음을 통해 공유


StringInfo.ParseCombiningCharacters 메서드

지정된 문자열 내에 있는 각 기본 문자, 상위 서로게이트 또는 제어 문자를 반환합니다.

네임스페이스: System.Globalization
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Shared Function ParseCombiningCharacters ( _
    str As String _
) As Integer()
‘사용 방법
Dim str As String
Dim returnValue As Integer()

returnValue = StringInfo.ParseCombiningCharacters(str)
public static int[] ParseCombiningCharacters (
    string str
)
public:
static array<int>^ ParseCombiningCharacters (
    String^ str
)
public static int[] ParseCombiningCharacters (
    String str
)
public static function ParseCombiningCharacters (
    str : String
) : int[]

매개 변수

  • str
    검색할 문자열입니다.

반환 값

지정된 문자열 내에 있는 각 기본 문자, 상위 서로게이트 또는 제어 문자의 인덱스(0부터 시작)가 포함되어 있는 정수의 배열입니다.

예외

예외 형식 조건

ArgumentNullException

str가 Null 참조(Visual Basic의 경우 Nothing)인 경우

설명

Unicode Standard에서는 서로게이트 쌍을 두 개의 코드 단위 시퀀스로 구성된 단일 추상 문자에 대한 코딩된 문자 표현으로 정의합니다. 서로게이트 쌍의 첫째 단위는 상위 서로게이트이고, 둘째 단위는 하위 서로게이트입니다. 상위 서로게이트는 U+D800부터 U+DBFF까지의 범위에 있는 유니코드 코드 포인트이고 하위 서로게이트는 U+DC00부터 U+DFFF까지의 범위에 있는 유니코드 코드 포인트입니다.

제어 문자는 유니코드 값이 U+007F이거나 U+0000에서 U+001F 또는 U+0080에서 U+009F 사이에 있는 문자입니다.

.NET Framework는 텍스트 요소를 단일 문자(서기소)로 표시되는 텍스트 단위로 정의합니다. 텍스트 요소에는 기본 문자, 서로게이트 쌍 또는 조합 문자 시퀀스가 있습니다. 또한 조합 문자 시퀀스를 기본 문자와 하나 이상의 조합 문자의 조합으로 정의합니다. 서로게이트 쌍은 기본 문자나 조합 문자를 나타낼 수 있습니다. 서로게이트 쌍과 조합 문자 시퀀스에 대한 자세한 내용은 http://www.unicode.org에 있는 Unicode Standard를 참조하십시오.

조합 문자 시퀀스가 잘못된 상태이면 해당 시퀀스에 있는 모든 조합 문자도 반환됩니다.

결과 배열의 각 인덱스는 텍스트 요소의 시작 부분으로, 기본 문자나 상위 서로게이트의 인덱스입니다.

각 요소의 길이는 연속된 인덱스 사이의 차이를 통해 쉽게 계산할 수 있습니다. 배열의 길이는 항상 문자열의 길이보다 짧거나 같습니다. 예를 들어, "\u4f00\u302a\ud800\udc00\u4f01" 문자열에 대해 이 메서드는 인덱스 0, 2 및 4를 반환합니다.

동일한 기능을 구현하는 멤버

SubstringByTextElements 메서드와 LengthInTextElements 속성은 .NET Framework 버전 2.0부터 ParseCombiningCharacters 메서드가 제공하는 기능을 간편하게 구현할 수 있습니다.

예제

다음 코드 예제에서는 ParseCombiningCharacters 메서드를 호출하는 방법을 보여 줍니다. 이 코드 예제는 StringInfo 클래스에 대해 제공되는 보다 큰 예제의 일부입니다.

using System;
using System.Text;
using System.Globalization;

public sealed class App {
   static void Main() {
      // The string below contains combining characters.
      String s = "a\u0304\u0308bc\u0327";

      // Show each 'character' in the string.
      EnumTextElements(s);

      // Show the index in the string where each 'character' starts.
      EnumTextElementIndexes(s);
   }

   // Show how to enumerate each real character (honoring surrogates) in a string.
   static void EnumTextElements(String s) {
      // This StringBuilder holds the output results.
      StringBuilder sb = new StringBuilder();

      // Use the enumerator returned from GetTextElementEnumerator 
      // method to examine each real character.
      TextElementEnumerator charEnum = StringInfo.GetTextElementEnumerator(s);
      while (charEnum.MoveNext()) {
         sb.AppendFormat(
           "Character at index {0} is '{1}'{2}",
           charEnum.ElementIndex, charEnum.GetTextElement(),
           Environment.NewLine);
      }

      // Show the results.
      Console.WriteLine("Result of GetTextElementEnumerator:");
      Console.WriteLine(sb);
   }

   // Show how to discover the index of each real character (honoring surrogates) in a string.
   static void EnumTextElementIndexes(String s) {
      // This StringBuilder holds the output results.
      StringBuilder sb = new StringBuilder();

      // Use the ParseCombiningCharacters method to 
      // get the index of each real character in the string.
      Int32[] textElemIndex = StringInfo.ParseCombiningCharacters(s);

      // Iterate through each real character showing the character and the index where it was found.
      for (Int32 i = 0; i < textElemIndex.Length; i++) {
         sb.AppendFormat(
            "Character {0} starts at index {1}{2}",
            i, textElemIndex[i], Environment.NewLine);
      }

      // Show the results.
      Console.WriteLine("Result of ParseCombiningCharacters:");
      Console.WriteLine(sb);
   }
}

// This code produces the following output.
//
// Result of GetTextElementEnumerator:
// Character at index 0 is 'a-"'
// Character at index 3 is 'b'
// Character at index 4 is 'c,'
// 
// Result of ParseCombiningCharacters:
// Character 0 starts at index 0
// Character 1 starts at index 3
// Character 2 starts at index 4
using namespace System;
using namespace System::Text;
using namespace System::Globalization;


// Show how to enumerate each real character (honoring surrogates)
// in a string.

void EnumTextElements(String^ combiningChars)
{
    // This StringBuilder holds the output results.
    StringBuilder^ sb = gcnew StringBuilder();

    // Use the enumerator returned from GetTextElementEnumerator
    // method to examine each real character.
    TextElementEnumerator^ charEnum =
        StringInfo::GetTextElementEnumerator(combiningChars);
    while (charEnum->MoveNext())
    {
        sb->AppendFormat("Character at index {0} is '{1}'{2}", 
            charEnum->ElementIndex, charEnum->GetTextElement(), 
            Environment::NewLine);
    }

    // Show the results.
    Console::WriteLine("Result of GetTextElementEnumerator:");
    Console::WriteLine(sb);
}


// Show how to discover the index of each real character
// (honoring surrogates) in a string.

void EnumTextElementIndexes(String^ combiningChars)
{
    // This StringBuilder holds the output results.
    StringBuilder^ sb = gcnew StringBuilder();

    // Use the ParseCombiningCharacters method to
    // get the index of each real character in the string.
    array <int>^ textElemIndex =
        StringInfo::ParseCombiningCharacters(combiningChars);

    // Iterate through each real character showing the character
    // and the index where it was found.
    for (int i = 0; i < textElemIndex->Length; i++)
    {
        sb->AppendFormat("Character {0} starts at index {1}{2}",
            i, textElemIndex[i], Environment::NewLine);
    }

    // Show the results.
    Console::WriteLine("Result of ParseCombiningCharacters:");
    Console::WriteLine(sb);
}

int main()
{

    // The string below contains combining characters.
    String^ combiningChars = L"a\u0304\u0308bc\u0327";

    // Show each 'character' in the string.
    EnumTextElements(combiningChars);

    // Show the index in the string where each 'character' starts.
    EnumTextElementIndexes(combiningChars);

};

// This code produces the following output.
//
// Result of GetTextElementEnumerator:
// Character at index 0 is 'a-"'
// Character at index 3 is 'b'
// Character at index 4 is 'c,'
//
// Result of ParseCombiningCharacters:
// Character 0 starts at index 0
// Character 1 starts at index 3
// Character 2 starts at index 4

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

StringInfo 클래스
StringInfo 멤버
System.Globalization 네임스페이스
SubstringByTextElements
LengthInTextElements