TextElementEnumeratorとは? わかりやすく解説

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 は、サロゲート ペアを 2 つのコード単位から成る単一の抽象文字を表すコード化文字表現として定義します。ペアの最初の単位が上位サロゲート、2 番目の単位が下位サロゲートとなります。Unicode Standard は、組み合わせ文字シーケンスを 1 つの基本文字と 1 つ以上の組み合わせ文字の組み合わせとして定義します。サロゲート ペアは、基本文字または組み合わせた文字を表すことができます。サロゲート ペアおよび組み合わせ文字シーケンスの詳細については、http://www.unicode.org の「The Unicode Standard」を参照してください。

テキスト要素の列挙子は、文字列内のデータを読み取ることだけを目的として使用されます。列挙子は、基になる文字列を変更するためには使用できません。

列挙子には、文字列への排他アクセス権はありません。

列挙子は、作成されるときに文字列の現在の状態のスナップショットを取得します。テキスト要素の追加、変更、削除などの変更が文字列に対して実行されると、スナップショットが同期されなくなり、列挙子は InvalidOperationException をスローします。同じ文字列から同時に作成された 2 つの列挙子が、その文字列の異なるスナップショットを持つこともできます。

文字列の最初のテキスト要素の前、または文字列の最後のテキスト要素の後に位置している列挙子は無効な状態です。列挙子が無効な状態の場合に Current を呼び出すと、必ず例外がスローされます。

初期状態では、列挙子は文字列の最初のテキスト要素の前に位置しています。Reset を実行した場合も、列挙子はこの位置に戻されます。したがって、列挙子を作成した後や Reset を呼び出した後に、文字列の最初のテキスト要素に列挙子を進めるためには、Current の値を読み取る前に MoveNext を呼び出す必要があります。

Current は、MoveNext または Reset が呼び出されるまでは同じオブジェクトを返します。

文字列の末尾を過ぎると列挙子が再び無効な状態になるため、MoveNext を呼び出すと false が返されます。MoveNext への最後の呼び出しで false が返された場合に Current を呼び出すと、例外がスローされます。

使用例使用例

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) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TextElementEnumerator メンバ
System.Globalization 名前空間
System.Collections.IEnumerator

TextElementEnumerator プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ ElementIndex 列挙子が現在位置しているテキスト要素のインデックスを取得します。
参照参照

関連項目

TextElementEnumerator クラス
System.Globalization 名前空間
System.Collections.IEnumerator

TextElementEnumerator メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

TextElementEnumerator クラス
System.Globalization 名前空間
System.Collections.IEnumerator

TextElementEnumerator メンバ

文字列のテキスト要素を列挙します。

TextElementEnumerator データ型で公開されるメンバを以下の表に示します。


パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ ElementIndex 列挙子が現在位置しているテキスト要素のインデックスを取得します。
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

TextElementEnumerator クラス
System.Globalization 名前空間
System.Collections.IEnumerator



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「TextElementEnumerator」の関連用語

TextElementEnumeratorのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TextElementEnumeratorのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS