StringInfo.GetTextElementEnumerator 메서드

정의

문자열의 텍스트 요소를 반복하는 열거자를 반환합니다.

오버로드

Name Description
GetTextElementEnumerator(String)

전체 문자열의 텍스트 요소를 반복하는 열거자를 반환합니다.

GetTextElementEnumerator(String, Int32)

지정된 인덱스에서 시작하여 문자열의 텍스트 요소를 반복하는 열거자를 반환합니다.

GetTextElementEnumerator(String)

Source:
StringInfo.cs
Source:
StringInfo.cs
Source:
StringInfo.cs
Source:
StringInfo.cs
Source:
StringInfo.cs

전체 문자열의 텍스트 요소를 반복하는 열거자를 반환합니다.

public:
 static System::Globalization::TextElementEnumerator ^ GetTextElementEnumerator(System::String ^ str);
public static System.Globalization.TextElementEnumerator GetTextElementEnumerator(string str);
static member GetTextElementEnumerator : string -> System.Globalization.TextElementEnumerator
Public Shared Function GetTextElementEnumerator (str As String) As TextElementEnumerator

매개 변수

str
String

반복할 문자열입니다.

반품

전체 문자열에 대한 A TextElementEnumerator 입니다.

예외

strnull입니다.

예제

다음 예제에서는 GetTextElementEnumerator 메서드를 호출하는 방법을 보여 줍니다. 이 예제는 클래스에 제공된 더 큰 예제의 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 'ā̈'
// Character at index 3 is 'b'
// Character at index 4 is 'ç'
//
// Result of ParseCombiningCharacters:
// Character 0 starts at index 0
// Character 1 starts at index 3
// Character 2 starts at index 4
Imports System.Text
Imports System.Globalization

Public Module Example
   Public Sub Main()
      ' The string below contains combining characters.
      Dim s As String = "a" + ChrW(&h0304) + ChrW(&h0308) + "bc" + ChrW(&h0327)

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

      ' Show the index in the string where each 'character' starts.
      EnumTextElementIndexes(s)
   End Sub

   ' Show how to enumerate each real character (honoring surrogates) in a string.
   Sub EnumTextElements(s As String)
      ' This StringBuilder holds the output results.
      Dim sb As New StringBuilder()

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

      ' Show the results.
      Console.WriteLine("Result of GetTextElementEnumerator:")
      Console.WriteLine(sb)
   End Sub

   ' Show how to discover the index of each real character (honoring surrogates) in a string.
   Sub EnumTextElementIndexes(s As String)
      ' This StringBuilder holds the output results.
      Dim sb As New StringBuilder()

      ' Use the ParseCombiningCharacters method to 
      ' get the index of each real character in the string.
      Dim textElemIndex() As Integer = StringInfo.ParseCombiningCharacters(s)

      ' Iterate through each real character showing the character and the index where it was found.
      For i As Int32 = 0 To textElemIndex.Length - 1
         sb.AppendFormat("Character {0} starts at index {1}{2}",
                         i, textElemIndex(i), Environment.NewLine)
      Next

      ' Show the results.
      Console.WriteLine("Result of ParseCombiningCharacters:")
      Console.WriteLine(sb)
   End Sub
End Module
' The example displays the following output:
'
'       Result of GetTextElementEnumerator:
'       Character at index 0 is 'ā̈'
'       Character at index 3 is 'b'
'       Character at index 4 is 'ç'
'       
'       Result of ParseCombiningCharacters:
'       Character 0 starts at index 0
'       Character 1 starts at index 3
'       Character 2 starts at index 4

설명

.NET은 텍스트 요소를 단일 문자, 즉 그래프로 표시되는 텍스트 단위로 정의합니다. 텍스트 요소는 기본 문자, 서로게이트 쌍 또는 결합 문자 시퀀스일 수 있습니다. 유니코드 표준은 서로게이트 쌍을 두 코드 단위의 시퀀스로 구성된 단일 추상 문자에 대한 코딩된 문자 표현으로 정의합니다. 여기서 쌍의 첫 번째 단위는 높은 서로게이트이고 두 번째 단위는 낮은 서로게이트입니다. 유니코드 표준은 결합 문자 시퀀스를 기본 문자와 하나 이상의 결합 문자의 조합으로 정의합니다. 서로게이트 쌍은 기본 문자 또는 결합 문자를 나타낼 수 있습니다.

텍스트 요소 열거자는 문자열의 데이터를 읽는 데만 사용됩니다. 기본 문자열을 수정할 수 없습니다. 열거자는 문자열에 대한 단독 액세스 권한이 없습니다.

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

처음에는 열거자가 문자열의 첫 번째 텍스트 요소 앞에 배치됩니다. Reset 또한 열거자를 이 위치로 다시 가져옵니다. 따라서 열거자를 만들거나 호출 MoveNext 한 후에 Reset 는 값을 읽기 Current전에 열거자를 문자열의 첫 번째 텍스트 요소로 이동하도록 호출해야 합니다.

Current 는 호출될 때까지 동일한 개체를 MoveNextReset 반환합니다.

문자열의 끝을 전달한 후 열거자가 다시 잘못된 상태가 되며 호출 MoveNext 이 반환됩니다 false. 호출 Current 은 반환false된 마지막 호출인 경우 예외를 MoveNext throw합니다.

추가 정보

적용 대상

GetTextElementEnumerator(String, Int32)

Source:
StringInfo.cs
Source:
StringInfo.cs
Source:
StringInfo.cs
Source:
StringInfo.cs
Source:
StringInfo.cs

지정된 인덱스에서 시작하여 문자열의 텍스트 요소를 반복하는 열거자를 반환합니다.

public:
 static System::Globalization::TextElementEnumerator ^ GetTextElementEnumerator(System::String ^ str, int index);
public static System.Globalization.TextElementEnumerator GetTextElementEnumerator(string str, int index);
static member GetTextElementEnumerator : string * int -> System.Globalization.TextElementEnumerator
Public Shared Function GetTextElementEnumerator (str As String, index As Integer) As TextElementEnumerator

매개 변수

str
String

반복할 문자열입니다.

index
Int32

반복을 시작할 인덱스(0부터 시작)입니다.

반품

에서 시작하는 index문자열에 대한 A TextElementEnumerator 입니다.

예외

strnull입니다.

index 가 유효한 인덱스 범위를 벗어났습니다 str.

설명

.NET은 텍스트 요소를 단일 문자, 즉 그래프로 표시되는 텍스트 단위로 정의합니다. 텍스트 요소는 기본 문자, 서로게이트 쌍 또는 결합 문자 시퀀스일 수 있습니다. 유니코드 표준은 서로게이트 쌍을 두 코드 단위의 시퀀스로 구성된 단일 추상 문자에 대한 코딩된 문자 표현으로 정의합니다. 여기서 쌍의 첫 번째 단위는 높은 서로게이트이고 두 번째 단위는 낮은 서로게이트입니다. 유니코드 표준은 결합 문자 시퀀스를 기본 문자와 하나 이상의 결합 문자의 조합으로 정의합니다. 서로게이트 쌍은 기본 문자 또는 결합 문자를 나타낼 수 있습니다.

텍스트 요소 열거자는 문자열의 데이터를 읽는 데만 사용됩니다. 기본 문자열을 수정할 수 없습니다. 열거자는 문자열에 대한 단독 액세스 권한이 없습니다.

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

처음에는 열거자가 문자열의 첫 번째 텍스트 요소 앞에 배치됩니다. Reset 또한 열거자를 이 위치로 다시 가져옵니다. 따라서 열거자를 만들거나 호출 MoveNext 한 후에 Reset 는 값을 읽기 Current전에 열거자를 문자열의 첫 번째 텍스트 요소로 이동하도록 호출해야 합니다.

Current 는 호출될 때까지 동일한 개체를 MoveNextReset 반환합니다.

문자열의 끝을 전달한 후 열거자가 다시 잘못된 상태가 되며 호출 MoveNext 이 반환됩니다 false. 호출 Current 은 반환false된 마지막 호출인 경우 예외를 MoveNext throw합니다.

추가 정보

적용 대상