System.Globalization.StringInfo Class

Assembly: Mscorlib.dll
Namespace: System.Globalization
Summary
Provides functionality to split a string into text elements and to iterate through those text elements.
C# Syntax:
[Serializable]
public class StringInfo
Remarks
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 a base character, a surrogate pair, or a combining character sequence. The Unicode Standard defines a surrogate pair as a coded character representation for a single abstract character that consists of a sequence of two code units, where the first unit of the pair is a high-surrogate and the second is a low-surrogate. The Unicode Standard defines a combining character sequence as a combination of a base character and one or more combining characters. A surrogate pair can represent a base character or a combining character. For more information on surrogate pairs and combining character sequences, see The Unicode Standard at http://www.unicode.org.
See also:
System.Globalization Namespace

System.Globalization.StringInfo Member List:

Public Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetNextTextElement Overloaded:
GetNextTextElement(string str)

Gets the first text element in a specified string.
GetNextTextElement Overloaded:
GetNextTextElement(string str, int index)

Gets the text element at the specified index of the specified string.
GetTextElementEnumerator Overloaded:
GetTextElementEnumerator(string str)

Returns an enumerator that can iterate through the text elements of the entire string.
GetTextElementEnumerator Overloaded:
GetTextElementEnumerator(string str, int index)

Returns an enumerator that can iterate through the text elements of the string, starting at the specified index.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ParseCombiningCharacters Returns the indexes of each base character, high-surrogate, or control character within the specified string.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Globalization.StringInfo Member Details

ctor #1
Summary:
Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public StringInfo();

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~StringInfo();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: GetNextTextElement(
   string str
)
Summary
Gets the first text element in a specified string.
C# Syntax:
public static string GetNextTextElement(
   string str
);
Parameters:

str

The string from which to get the text element.

Return Value:
A string containing the first text element in the specified string.
Exceptions
Exception Type Condition
ArgumentNullException str is null.
Remarks
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 a base character, a surrogate pair, or a combining character sequence. The Unicode Standard defines a surrogate pair as a coded character representation for a single abstract character that consists of a sequence of two code units, where the first unit of the pair is a high-surrogate and the second is a low-surrogate. The Unicode Standard defines a combining character sequence as a combination of a base character and one or more combining characters. A surrogate pair can represent a base character or a combining character. For more information on surrogate pairs and combining character sequences, see The Unicode Standard at http://www.unicode.org.

This method only returns the first text element. To iterate through the text elements of the string, use the TextElementEnumerator generated by the StringInfo.GetTextElementEnumerator method.

See also:
StringInfo.GetTextElementEnumerator | StringInfo.ParseCombiningCharacters

Return to top


Overloaded Method: GetNextTextElement(
   string str,
   int index
)
Summary
Gets the text element at the specified index of the specified string.
C# Syntax:
public static string GetNextTextElement(
   string str,
   int index
);
Parameters:

str

The string from which to get the text element.

index

The zero-based index at which the text element starts.

Return Value:
A string containing the text element at the specified index of the specified string.
Exceptions
Exception Type Condition
ArgumentNullException str is null.
ArgumentOutOfRangeException index is outside the range of valid indexes for str.
Remarks
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 a base character, a surrogate pair, or a combining character sequence. The Unicode Standard defines a surrogate pair as a coded character representation for a single abstract character that consists of a sequence of two code units, where the first unit of the pair is a high-surrogate and the second is a low-surrogate. The Unicode Standard defines a combining character sequence as a combination of a base character and one or more combining characters. A surrogate pair can represent a base character or a combining character. For more information on surrogate pairs and combining character sequences, see The Unicode Standard at http://www.unicode.org.

This method only returns the first text element of the substring that starts at the specified index. To iterate through the text elements of the string, use the TextElementEnumerator generated by the StringInfo.GetTextElementEnumerator method.

See also:
StringInfo.GetTextElementEnumerator | StringInfo.ParseCombiningCharacters

Return to top


Overloaded Method: GetTextElementEnumerator(
   string str
)
Summary
Returns an enumerator that can iterate through the text elements of the entire string.
C# Syntax:
public static TextElementEnumerator GetTextElementEnumerator(
   string str
);
Parameters:

str

The string to iterate through.

Return Value:
A TextElementEnumerator for the entire string.
Exceptions
Exception Type Condition
ArgumentNullException str is null.
Remarks
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 a base character, a surrogate pair, or a combining character sequence. The Unicode Standard defines a surrogate pair as a coded character representation for a single abstract character that consists of a sequence of two code units, where the first unit of the pair is a high-surrogate and the second is a low-surrogate. The Unicode Standard defines a combining character sequence as a combination of a base character and one or more combining characters. A surrogate pair can represent a base character or a combining character. For more information on surrogate pairs and combining character sequences, see The Unicode Standard at http://www.unicode.org.

Text element enumerators are intended to be used only to read data in the string. Enumerators cannot be used to modify the underlying string.

The enumerator does not have exclusive access to the string.

When an enumerator is created, it takes a snapshot of the current state of the string. If changes are made to the string, such as adding, modifying, or deleting text elements, the snapshot gets out of sync and the enumerator throws an InvalidOperationException. Two enumerators created from the same string at the same time can have different snapshots of the string.

The enumerator is in an invalid state if it is positioned before the first text element in the string or after the last text element in the string. Whenever the enumerator is in an invalid state, calling TextElementEnumerator.Current throws an exception.

Initially, the enumerator is positioned before the first text element in the string. TextElementEnumerator.Reset also brings the enumerator back to this position. Therefore, after an enumerator is created or after a TextElementEnumerator.Reset, TextElementEnumerator.MoveNext must be called to advance the enumerator to the first text element of the string before reading the value of TextElementEnumerator.Current.

TextElementEnumerator.Current returns the same object until either TextElementEnumerator.MoveNext or TextElementEnumerator.Reset is called.

After the end of the string is passed, the enumerator is again in an invalid state and calling TextElementEnumerator.MoveNext returns false. Calling TextElementEnumerator.Current throws an exception if the last call to TextElementEnumerator.MoveNext returned false.

See also:
TextElementEnumerator

Return to top


Overloaded Method: GetTextElementEnumerator(
   string str,
   int index
)
Summary
Returns an enumerator that can iterate through the text elements of the string, starting at the specified index.
C# Syntax:
public static TextElementEnumerator GetTextElementEnumerator(
   string str,
   int index
);
Parameters:

str

The string to iterate through.

index

The zero-based index at which to start iterating.

Return Value:
A TextElementEnumerator for the string starting at index.
Exceptions
Exception Type Condition
ArgumentNullException str is null.
ArgumentOutOfRangeException index is outside the range of valid indexes for str.
Remarks
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 a base character, a surrogate pair, or a combining character sequence. The Unicode Standard defines a surrogate pair as a coded character representation for a single abstract character that consists of a sequence of two code units, where the first unit of the pair is a high-surrogate and the second is a low-surrogate. The Unicode Standard defines a combining character sequence as a combination of a base character and one or more combining characters. A surrogate pair can represent a base character or a combining character. For more information on surrogate pairs and combining character sequences, see The Unicode Standard at http://www.unicode.org.

Text element enumerators are intended to be used only to read data in the string. Enumerators cannot be used to modify the underlying string.

The enumerator does not have exclusive access to the string.

When an enumerator is created, it takes a snapshot of the current state of the string. If changes are made to the string, such as adding, modifying or deleting text elements, the snapshot gets out of sync and the enumerator throws an InvalidOperationException. Two enumerators created from the same string at the same time can have different snapshots of the string.

The enumerator is in an invalid state if it is positioned before the first text element in the string or after the last text element in the string. Whenever the enumerator is in an invalid state, calling TextElementEnumerator.Current throws an exception.

Initially, the enumerator is positioned before the first text element in the string. TextElementEnumerator.Reset also brings the enumerator back to this position. Therefore, after an enumerator is created or after a TextElementEnumerator.Reset, TextElementEnumerator.MoveNext must be called to advance the enumerator to the first text element of the string before reading the value of TextElementEnumerator.Current.

TextElementEnumerator.Current returns the same object until either TextElementEnumerator.MoveNext or TextElementEnumerator.Reset is called.

After the end of the string is passed, the enumerator is again in an invalid state and calling TextElementEnumerator.MoveNext returns false. Calling TextElementEnumerator.Current throws an exception if the last call to TextElementEnumerator.MoveNext returned false.

See also:
TextElementEnumerator

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ParseCombiningCharacters(
   string str
)
Summary
Returns the indexes of each base character, high-surrogate, or control character within the specified string.
C# Syntax:
public static int[] ParseCombiningCharacters(
   string str
);
Parameters:

str

The string to search.

Return Value:
An array of integers that contains the zero-based indexes of each base character, high-surrogate, or control character within the specified string.
Exceptions
Exception Type Condition
ArgumentNullException str is null.
Remarks
The Unicode Standard defines a surrogate pair as a coded character representation for a single abstract character that consists of a sequence of two code units, where the first unit of the pair is a high-surrogate and the second is a low-surrogate. A high-surrogate is a Unicode code point in the range U+D800 through U+DBFF and a low-surrogate is a Unicode code point in the range U+DC00 through U+DFFF.

A control character is a character whose Unicode value is U+007F or in the range U+0000 through U+001F or U+0080 through U+009F.

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 a base character, a surrogate pair, or a combining character sequence. The Unicode Standard defines a combining character sequence as a combination of a base character and one or more combining characters. A surrogate pair can represent a base character or a combining character. For more information on surrogate pairs and combining character sequences, see The Unicode Standard at http://www.unicode.org.

If a combining character sequence is invalid, every combining character in that sequence is also returned.

Each index in the resulting array is the beginning of a text element; that is, the index of the base character or the high-surrogate.

The length of each element is easily computed as the difference between successive indexes. The length of the array will always be less than or equal to the length of the string. For example, given the string "\u4f00\u302a\ud800\udc00\u4f01", this method would return the indexes 0, 2, and 4.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.