TextElementEnumerator 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
枚举字符串的文本元素。
public ref class TextElementEnumerator : System::Collections::IEnumeratorpublic 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.IEnumeratortype TextElementEnumerator = class
    interface IEnumerator[<System.Serializable>]
type TextElementEnumerator = class
    interface IEnumerator[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type TextElementEnumerator = class
    interface IEnumeratorPublic 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 值。 例如,拉丁文大写字母 A (U+0041) 和拉丁文小写字母 AE (U+00E6) 都是基字符。 
- 组合字符序列,由一个基字符和一个或多个组合字符组成。 例如,LATIN 大写字母 A (U+0041) 后跟 COMBINING MACRON (U+0304) 是组合字符序列。 
- 代理项对, Unicode 标准 将它定义为单个抽象字符的编码字符表示形式,该抽象字符由两个代码单元组成的序列组成:高代理项和低代理项。 代理项对用于将 Unicode 基本多语言平面外部的字符表示为 UTF-16 编码字符。 例如,哥特字母 SAUIL (U+10343) 以 UTF-16 编码表示为值0xD800的高代理项和值0xDF43的低代理项。 代理项对可以表示基字符或组合字符。 
类 TextElementEnumerator 允许你使用字符串中的文本元素,而不是单个 Char 对象。
通过将字符串传递给 方法,实例化 TextElementEnumerator 表示特定字符串 StringInfo.GetTextElementEnumerator 的 对象。 这将返回一个枚举器,该枚举器位于字符串中的第一个文本元素之前。 Reset调用 方法还会使枚举器回到此位置。 由于这表示无效状态,因此您必须调用 MoveNext 将枚举器前进到字符串的第一个文本元素,然后再读取 属性的值 Current 以返回当前文本元素。
使用 TextElementEnumerator 对象时,你负责定位枚举器。 在调用 MoveNext 或 Reset之前, Current 属性返回相同的文本元素。 如果枚举器位于字符串中的第一个文本元素之前或最后一个文本元素之后,则该枚举器处于无效状态。 当枚举器处于无效状态时,尝试检索属性的值 Current 会引发异常。 可以通过测试 属性false的返回值MoveNext是否为 来确定枚举器是否处于无效状态。
对象TextElementEnumerator表示实例化对象时TextElementEnumerator字符串变量或字符串文本的当前状态的快照。 请注意:
- 文本元素枚举器只能用于读取字符串中的数据。 它们无法修改基础字符串。 
- 枚举器不具有对它所表示的字符串的独占访问权限。 创建枚举器后,可以修改字符串变量。 
- 对象 TextElementEnumerator 枚举实例化对象时 TextElementEnumerator 字符串中存在的文本元素。 如果之后修改了该变量,则不会反映对字符串变量的任何后续更改。 
- TextElementEnumerator由于 类不重写 Object.Equals,因此表示同一字符串的两TextElementEnumerator个对象将被视为不相等。 
属性
| Current | 获取字符串中的当前文本元素。 | 
| ElementIndex | 获取枚举数当前置于其上的文本元素的索引。 | 
方法
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetTextElement() | 获取字符串中的当前文本元素。 | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| MoveNext() | 将枚举数前移到字符串的下一个文本元素。 | 
| Reset() | 将枚举数设置为其初始位置,该位置位于字符串中第一个文本元素之前。 | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) |