Enumerates the text elements of a string.
Assemblies: mscorlib (in mscorlib.dll)
System.Globalization (in System.Globalization.dll)
Thetype exposes the following members.
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetTextElement||Gets the current text element in the string.|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|MoveNext||Advances the enumerator to the next text element of the string.|
|Reset||Sets the enumerator to its initial position, which is before the first text element in the string.|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
The .NET Framework defines a text element as a unit of text that is displayed as a single character, that is, a grapheme. A text element can be any of the following:
A base character, which is represented as a single Char value. For example, LATIN CAPITAL LETTER A (U+0041) and LATIN SMALL LETTER AE (U+00E6) are base characters.
A combining character sequence, which consists of a base character and one or more combining characters. For example, example, LATIN CAPITAL LETTER A (U+0041) followed by COMBINING MACRON (U+0304) is a combining character sequence.
Surrogate pairs, which the Unicode Standard defines as a coded character representation for a single abstract character that consists of a sequence of two code units: a high surrogate, and a low surrogate. Surrogate pairs are used to represent characters outside of the Unicode Basic Multilingual Plane as UTF-8 encoded characters. For example, GOTHIC LETTER SAUIL (U+10343) is represented in UTF-8 encoding as a high surrogate whose value is 0xD800 and a low surrogate whose value is 0xDF43. A surrogate pair can represent a base character or a combining character.
The class allows you to work with the text elements in a string rather than with single Char objects.
You instantiate a object that represents a particular string by passing the string to the StringInfo.GetTextElementEnumerator method. This returns an enumerator that is positioned before the first text element in the string. Calling the Reset method also brings the enumerator back to this position. Because this represents an invalid state, you must call MoveNext to advance the enumerator to the first text element of the string before reading the value of the Current property to return the current text element.
When working with a object, you are responsible for positioning the enumerator. The Current property returns the same text element until you call either MoveNext or Reset. The enumerator is in an invalid state if it is positioned before the first text element or after the last text element in the string. When the enumerator is in an invalid state, attempting to retrieve the value of the Current property throws an exception. You can determine whether the enumerator is in an invalid state by testing whether the return value of the MoveNext property is false.
The object represents a snapshot of the current state of a string variable or string literal at the moment that the object is instantiated. Note that:
Text element enumerators can only be used to read data in a string. They cannot modify the underlying string.
An enumerator does not have exclusive access to the string that it represents. A string variable can be modified after the enumerator is created.
A object enumerates the text elements present in the string at the time that the object was instantiated. It does not reflect any subsequent changes to the string variable if that variable is modified afterward.
Because the class does not override Object.Equals, two objects that represent the same string will be considered unequal.
.NET FrameworkSupported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
XNA FrameworkSupported in: 3.0, 2.0, 1.0
Portable Class LibrarySupported in: Portable Class Library
Supported in: Windows Phone 8.1
Supported in: Windows Phone Silverlight 8.1
Supported in: Windows Phone Silverlight 8