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では、1 つの文字 (つまり grapheme) として表示されるテキストの単位としてテキスト要素を定義します。 テキスト要素には、次のいずれかを指定できます。

  • 1 つの Char 値として表される基本文字。 たとえば、英大文字 A (U+0041) とラテン小文字 AE (U+00E6) は基本文字です。

  • 基本文字と 1 つ以上の結合文字で構成される結合文字シーケンス。 たとえば、LATIN CAPITAL LETTER A (U+0041) の後に COMBINING MACRON (U+0304) が続く文字シーケンスを結合します。

  • サロゲート ペア。 Unicode 標準 では、高サロゲートと低サロゲートの 2 つのコード単位のシーケンスで構成される 1 つの抽象文字のコード化された文字表現として定義されます。 サロゲート ペアは、Unicode Basic 多言語プレーン以外の文字を UTF-16 でエンコードされた文字として表すために使用されます。 たとえば、GOTHIC LETTER SAUIL (U+10343) は UTF-16 エンコードで、値が0xD800で、値が0xDF43低いサロゲートとして表されます。 サロゲート ペアは、基本文字または結合文字を表すことができます。

TextElementEnumeratorクラスを使用すると、1 つのCharオブジェクトではなく、文字列内のテキスト要素を操作できます。

特定の文字列を TextElementEnumerator 表す オブジェクトをインスタンス化するには、 メソッドに文字列を StringInfo.GetTextElementEnumerator 渡します。 これにより、文字列内の最初のテキスト要素の前に配置された列挙子が返されます。 メソッドを Reset 呼び出すと、列挙子もこの位置に戻ります。 これは無効な状態を表しているため、現在のテキスト要素を返すプロパティの値を読み取る前に、 を呼び出 MoveNext して列挙子を文字列の最初の Current テキスト要素に進める必要があります。

オブジェクトを操作する TextElementEnumerator 場合は、列挙子を配置する必要があります。 または をMoveNextReset呼び出すまで、プロパティはCurrent同じテキスト要素を返します。 列挙子が最初のテキスト要素の前または文字列の最後のテキスト要素の後に配置されている場合、列挙子は無効な状態になります。 列挙子が無効な状態の場合、 プロパティの値を取得しようとすると例外が Current スローされます。 列挙子が無効な状態であるかどうかを確認するには、 プロパティfalseMoveNext戻り値が であるかどうかをテストします。

オブジェクトは TextElementEnumerator 、オブジェクトがインスタンス化された時点での文字列変数または文字列リテラルの現在の状態のスナップショットを TextElementEnumerator 表します。 以下の点に注意してください。

  • テキスト要素列挙子は、文字列内のデータの読み取りにのみ使用できます。 基になる文字列を変更することはできません。

  • 列挙子は、それが表す文字列に対する排他的アクセス権を持っていません。 文字列変数は、列挙子の作成後に変更できます。

  • オブジェクトは TextElementEnumerator 、オブジェクトがインスタンス化された時点で文字列に存在するテキスト要素を TextElementEnumerator 列挙します。 その変数が後で変更された場合、文字列変数に対する後続の変更は反映されません。

  • クラスは TextElementEnumerator をオーバーライド Object.Equalsしないため、同じ文字列を表す 2 つの TextElementEnumerator オブジェクトは等しくないと見なされます。

プロパティ

Current

文字列内の現在のテキスト要素を取得します。

ElementIndex

列挙子が現在位置しているテキスト要素のインデックスを取得します。

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetTextElement()

文字列内の現在のテキスト要素を取得します。

GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
MoveNext()

列挙子を文字列の次のテキスト要素に進めます。

Reset()

列挙子を初期位置、つまり文字列の最初のテキスト要素の前に設定します。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

こちらもご覧ください