TextElementEnumerator 클래스

정의

문자열의 텍스트 요소를 열거합니다.

public ref class TextElementEnumerator : System::Collections::IEnumerator
public class TextElementEnumerator : System.Collections.IEnumerator
[System.Serializable]
public class TextElementEnumerator : System.Collections.IEnumerator
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class TextElementEnumerator : System.Collections.IEnumerator
type TextElementEnumerator = class
    interface IEnumerator
[<System.Serializable>]
type TextElementEnumerator = class
    interface IEnumerator
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type TextElementEnumerator = class
    interface IEnumerator
Public Class TextElementEnumerator
Implements IEnumerator
상속
TextElementEnumerator
특성
구현

예제

다음 예제에서는 클래스를 TextElementEnumerator 사용하여 문자열의 텍스트 요소를 열거합니다.

using namespace System;
using namespace System::Globalization;
int main()
{

   // Creates and initializes a String containing the following:
   //   - a surrogate pair (high surrogate U+D800 and low surrogate U+DC00)
   //   - a combining character sequence (the Latin small letter S"a" followed by the combining grave accent)
   //   - a base character (the ligature S"")
   String^ myString = L"\xD800\xDC00"
   L"a\u0300\u00C6";

   // Creates and initializes a TextElementEnumerator for myString.
   TextElementEnumerator^ myTEE = StringInfo::GetTextElementEnumerator( myString );

   // Displays the values returned by ElementIndex, Current and GetTextElement.
   // Current and GetTextElement return a String* containing the entire text element.
   Console::WriteLine( "Index\tCurrent\tGetTextElement" );
   myTEE->Reset();
   while ( myTEE->MoveNext() )
      Console::WriteLine( "[{0}]:\t {1}\t {2}", myTEE->ElementIndex, myTEE->Current, myTEE->GetTextElement() );
}

/*
This code produces the following output.  The question marks take the place of high and low surrogates.

Index   Current GetTextElement
[0]:    𐀀       𐀀
[2]:    à       à
[4]:    Æ       Æ

*/
using System;
using System.Globalization;

public class SamplesTextElementEnumerator  {

   public static void Main()  {

      // Creates and initializes a String containing the following:
      //   - a surrogate pair (high surrogate U+D800 and low surrogate U+DC00)
      //   - a combining character sequence (the Latin small letter "a" followed by the combining grave accent)
      //   - a base character (the ligature "")
      String myString = "\uD800\uDC00\u0061\u0300\u00C6";

      // Creates and initializes a TextElementEnumerator for myString.
      TextElementEnumerator myTEE = StringInfo.GetTextElementEnumerator( myString );

      // Displays the values returned by ElementIndex, Current and GetTextElement.
      // Current and GetTextElement return a string containing the entire text element.
      Console.WriteLine( "Index\tCurrent\tGetTextElement" );
      myTEE.Reset();
      while (myTEE.MoveNext())  {
         Console.WriteLine( "[{0}]:\t{1}\t{2}", myTEE.ElementIndex, myTEE.Current, myTEE.GetTextElement() );
      }
   }
}

/*
This code produces the following output.  The question marks take the place of high and low surrogates.

Index   Current GetTextElement
[0]:    𐀀       𐀀
[2]:    à       à
[4]:    Æ       Æ

*/
Imports System.Globalization

Public Class SamplesTextElementEnumerator

   Public Shared Sub Main()

      ' Creates and initializes a String containing the following:
      '   - a surrogate pair (high surrogate U+D800 and low surrogate U+DC00)
      '   - a combining character sequence (the Latin small letter "a" followed by the combining grave accent)
      '   - a base character (the ligature "")
      Dim myString As String = ChrW(&HD800) & ChrW(&HDC00) & ChrW(&H0061) & ChrW(&H0300) & ChrW(&H00C6)

      ' Creates and initializes a TextElementEnumerator for myString.
      Dim myTEE As TextElementEnumerator = StringInfo.GetTextElementEnumerator( myString )

      ' Displays the values returned by ElementIndex, Current and GetTextElement.
      ' Current and GetTextElement return a string containing the entire text element.
      Console.WriteLine("Index" + ControlChars.Tab + "Current" + ControlChars.Tab + "GetTextElement")
      myTEE.Reset()
      While myTEE.MoveNext()
         Console.WriteLine("[{0}]:" + ControlChars.Tab + "{1}" + ControlChars.Tab + "{2}", myTEE.ElementIndex, myTEE.Current, myTEE.GetTextElement())
      End While

   End Sub

End Class

'This code produces the following output.  The question marks take the place of high and low surrogates.
'
'Index   Current GetTextElement
'[0]:    𐀀       𐀀
'[2]:    à       à
'[4]:    Æ       Æ

설명

.NET Framework 텍스트 요소를 단일 문자, 즉 그래프로 표시되는 텍스트 단위로 정의합니다. 텍스트 요소는 다음 중 어느 것이든 될 수 있습니다.

  • 단일 Char 값으로 표현되는 기본 문자입니다. 예를 들어 LATIN CAPITAL LETTER A(U+0041) 및 LATIN SMALL LETTER AE(U+00E6)는 기본 문자입니다.

  • 기본 문자와 하나 이상의 결합 문자로 구성된 결합 문자 시퀀스입니다. 예를 들어 LATIN CAPITAL LETTER A(U+0041)와 COMBINING MACRON(U+0304)은 결합 문자 시퀀스입니다.

  • 유니코드 표준이 높은 서로게이트와 낮은 서로게이트라는 두 코드 단위의 시퀀스로 구성된 단일 추상 문자에 대해 코딩된 문자 표현으로 정의하는 서로게이트 쌍입니다. 서로게이트 쌍은 유니코드 기본 다국어 평면 외부의 문자를 UTF-16으로 인코딩된 문자로 나타내는 데 사용됩니다. 예를 들어 GOTHIC LETTER SAUIL(U+10343)은 UTF-16 인코딩에서 값이 0xD800 높은 서로게이트로, 값이 0xDF43 낮은 서로게이트로 표시됩니다. 서로게이트 쌍은 기본 문자 또는 결합 문자를 나타낼 수 있습니다.

클래스 TextElementEnumerator 를 사용하면 단일 Char 개체가 아닌 문자열의 텍스트 요소를 사용할 수 있습니다.

메서드에 문자열을 TextElementEnumerator 전달하여 특정 문자열을 나타내는 개체를 StringInfo.GetTextElementEnumerator 인스턴스화합니다. 문자열의 첫 번째 텍스트 요소 앞에 배치되는 열거자를 반환합니다. 메서드를 호출하면 Reset 열거자가 이 위치로 돌아갑니다. 잘못된 상태를 나타내므로 현재 텍스트 요소를 반환하려면 속성 값을 읽기 전에 열거자를 문자열의 Current 첫 번째 텍스트 요소로 이동하도록 호출 MoveNext 해야 합니다.

개체를 TextElementEnumerator 사용할 때는 열거자의 위치를 지정해야 합니다. 속성은 Current 둘 중 하나 MoveNext 또는 를 호출할 때까지 동일한 텍스트 요소를 반환합니다 Reset. 열거자가 첫 번째 텍스트 요소 앞이나 문자열의 마지막 텍스트 요소 앞에 있는 경우 잘못된 상태입니다. 열거자가 잘못된 상태이면 속성 값을 Current 검색하려고 하면 예외가 throw됩니다. 속성의 반환 값 MoveNext 이 있는지 여부를 테스트하여 열거자가 잘못된 상태인지 여부를 확인할 수 있습니다 false.

개체는 TextElementEnumerator 개체가 인스턴스화되는 순간 문자열 변수 또는 문자열 리터럴의 현재 상태에 대한 TextElementEnumerator 스냅샷을 나타냅니다. 다음 사항에 유의하세요.

  • 텍스트 요소 열거자는 문자열의 데이터를 읽는 데만 사용할 수 있습니다. 기본 문자열을 수정할 수 없습니다.

  • 열거자는 나타내는 문자열에 대한 단독 액세스 권한이 없습니다. 열거자를 만든 후에 문자열 변수를 수정할 수 있습니다.

  • 개체는 TextElementEnumerator 개체가 인스턴스화될 때 TextElementEnumerator 문자열에 있는 텍스트 요소를 열거합니다. 나중에 해당 변수를 수정하는 경우 문자열 변수에 대한 후속 변경 내용이 반영되지 않습니다.

  • 클래스가 재정Object.EqualsTextElementEnumerator 되지 않으므로 동일한 문자열을 나타내는 두 개체 TextElementEnumerator 는 같지 않은 것으로 간주됩니다.

속성

Current

문자열의 현재 텍스트 요소를 가져옵니다.

ElementIndex

열거자가 현재 위치하고 있는 텍스트 요소의 인덱스를 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetTextElement()

문자열의 현재 텍스트 요소를 가져옵니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
MoveNext()

열거자를 문자열의 다음 텍스트 요소로 이동합니다.

Reset()

문자열의 첫째 텍스트 요소 앞의 초기 위치에 열거자를 지정합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보