Figure 12-4: Result of ParseCombiningCharacters Note To see the message box text in Figure 12-3 correctly, I had to open the Windows Display Properties dialog box and change the font used by message box text to Lucida Sans Unicode because this font contains glyphs for these combining characters. This is also why I don’t have the code display the results to the console. In this example, I’m calling StringInfo’s static GetTextElementEnumerator method. I pass a String to this method and it returns a TextElementEnumerator object. I can now use this enumerator object as I would any other enumerator object. The TextElementEnumerator object also offers a read-only ElementIndex property that returns the index of the code value in the original string where the character begins and a GetTextElement method that returns a string consisting of all the code values necessary to make up the character. In addition, StringInfo provides a static ParseCombiningCharacters method that parses a string and returns an array of Int32s. Each element in the returned array is an index of a code-point unit that is the start of an abstract character. The .NET Framework SDK documentation shows an example of how to call this method. Note that the StringInfo class defines a public constructor, but this is a bug; there’s never a reason to construct an instance of a StringInfo.
Other String Operations The String type also offers methods that allow you to copy a string or parts of it. Table 123 summarizes these methods. Table 12-3: Methods for Copying Strings Member
Type Method
Description
Clone
Instance
Returns a reference to the same object (this). This is OK because String objects are immutable. This method implements String’s ICloneable interface.
Copy
Static
Returns a new string that is a duplicate of the specified string. This method is rarely