다음을 통해 공유


TextElementEnumerator 클래스

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

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

구문

‘선언
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class TextElementEnumerator
    Implements IEnumerator
‘사용 방법
Dim instance As TextElementEnumerator
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class TextElementEnumerator : IEnumerator
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class TextElementEnumerator : IEnumerator
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class TextElementEnumerator implements IEnumerator
SerializableAttribute 
ComVisibleAttribute(true) 
public class TextElementEnumerator implements IEnumerator

설명

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

텍스트 요소 열거자는 문자열의 데이터를 읽는 데만 사용되며, 내부 문자열을 수정하는 데는 사용할 수 없습니다.

열거자는 문자열에 단독으로 액세스할 수 없습니다.

열거자가 만들어질 때 문자열의 현재 상태 스냅샷이 만들어집니다. 문자열에 텍스트 요소 추가, 수정 또는 삭제와 같은 변경 내용이 있는 경우 스냅샷은 동기화되지 않으며 열거자는 InvalidOperationException을 throw합니다. 같은 문자열에서 열거자 두 개를 동시에 만들어도 스냅샷은 서로 다를 수 있습니다.

열거자가 문자열의 첫째 텍스트 요소 앞이나 마지막 요소 뒤에 있으면 잘못된 상태입니다. 열거자가 잘못된 상태인 경우 Current를 호출하면 예외가 throw됩니다.

처음에는 열거자가 문자열의 첫째 텍스트 요소 앞에 배치됩니다. 그러면 Reset은 열거자를 이 위치로 다시 가져옵니다. 따라서 열거자를 만들거나 Reset을 호출한 후에는 MoveNext를 호출하여 열거자를 문자열의 첫째 텍스트 요소로 보낸 다음 Current 값을 읽어야 합니다.

CurrentMoveNext 또는 Reset가 호출될 때까지 같은 개체를 반환합니다.

문자열의 끝이 전달되면 열거자는 다시 잘못된 상태로 되고 MoveNext를 호출하면 false가 반환됩니다. MoveNext를 마지막으로 호출하여 false가 반환된 경우 Current를 호출하면 예외가 throw됩니다.

예제

다음 코드 예제에서는 TextElementEnumerator에서 반환한 값을 보여 줍니다.

Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

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 'Main 

End Class 'SamplesTextElementEnumerator

'This code produces the following output.  The question marks take the place of high and low surrogates.
'
'Index   Current GetTextElement
'[0]:    ??      ??
'[2]:    a`      a`
'[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]:    a`      a`
[4]:           

*/
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]:    a`      a`
[4]:           

*/
import System.*;
import System.Globalization.*;

public class SamplesTextElementEnumerator
{
    public static void main(String[] args)
    {
        // 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}", 
                System.Convert.ToString(myTEE.get_ElementIndex()),
                System.Convert.ToString(myTEE.get_Current()),
                myTEE.GetTextElement());
        }
    } //main
} //SamplesTextElementEnumerator

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

Index   Current GetTextElement
[0]:    ??      ??
[2]:    a`      a`
[4]:                      

*/

상속 계층 구조

System.Object
  System.Globalization.TextElementEnumerator

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

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에서 지원

참고 항목

참조

TextElementEnumerator 멤버
System.Globalization 네임스페이스
System.Collections.IEnumerator