See Also: Char Members
The dnprdnshort uses the char structure to represent a Unicode character. The Unicode Standard identifies each Unicode character with a unique 21-bit scalar number called a code point, and defines the UTF-16 encoding form that specifies how a code point is encoded into a sequence of one or more 16-bit values. Each 16-bit value ranges from hexadecimal 0x0000 through 0xFFFF and is stored in a char structure. The value of a char object is its 16-bit numeric (ordinal) value.
A string object is a sequential collection of char structures that represents a string of text. Most Unicode characters can be represented by a single char object, but a character that is encoded as a base character, surrogate pair, and/or combining character sequence is represented by multiple char objects. For this reason, a char structure in a string object is not necessarily equivalent to a single Unicode character.
Multiple 16-bit code units are used to represent single Unicode characters in the following cases:
Glyphs, which may consist of a single character or of a base character followed by one or more combining characters. For example, the character ä is represented by a char object whose code unit is U+0061 followed by a char object whose code unit is U+0308. (The character ä can also be defined by a single char object that has a code unit of U+00E4.) The following example illustrates that the character ä consists of two char objects.
code reference: System.Char.Class#1
Characters outside the Unicode Basic Multilingual Plane (BMP). Unicode supports sixteen planes in addition to the BMP, which represents plane 0. A Unicode code point is represented in UTF-32 by a 21-bit value that includes the plane. For example, U+1D160 represents the MUSICAL SYMBOL EIGHTH NOTE character. Because UTF-16 encoding has only 16 bits, characters outside the BMP are represented by surrogate pairs in UTF-16. The following example illustrates that the UTF-32 equivalent of U+1D160, the MUSICAL SYMBOL EIGHTH NOTE character, is U+D834 U+DD60. U+D834 is the high surrogate; high surrogates range from U+D800 through U+DBFF. U+DD60 is the low surrogate; low surrogates range from U+DC00 through U+DFFF.
code reference: System.Char.Class#2
Because a single character can be represented by multiple char objects, it is not always meaningful to work with individual char objects. For instance, the following example converts the Unicode code points that represent the Aegean numbers zero through 9 to UTF-16 encoded code units. Because it erroneously equates char objects with characters, it inaccurately reports that the resulting string has 20 characters.
code reference: System.Char.Class#3
You can do the following to avoid the assumption that a char object represents a single character.
You can work with a string object in its entirety instead of working with its individual characters to represent and analyze linguistic content.
You can use the System.Globalization.StringInfo class to work with text elements instead of individual char objects. The following example uses the System.Globalization.StringInfo object to count the number of text elements in a string that consists of the Aegean numbers zero through nine. Because it considers a surrogate pair a single character, it correctly reports that the string contains ten characters.
code reference: System.Char.Class#4
If a string contains a base character that has one or more combining characters, you can call the string.Normalize method to convert the substring to a single UTF-16 encoded code unit. The following example calls the string.Normalize method to convert the base character U+0061 (LATIN SMALL LETTER A) and combining character U+0308 (COMBINING DIAERESIS) to U+00E4 (LATIN SMALL LETTER A WITH DIAERESIS).
code reference: System.Char.Class#5
|Compare char objects|
|Convert a code point to a string|
|Convert a char object or a surrogate pair of char objects to a code point|
|Get the Unicode category of a character|
|Determine whether a character is in a particular Unicode category such as digit, letter, punctuation, control character, and so on||
erload:System.Char.IsControl, erload:System.Char.IsDigit, erload:System.Char.IsHighSurrogate, erload:System.Char.IsLetter, erload:System.Char.IsLetterOrDigit, erload:System.Char.IsLower, erload:System.Char.IsLowSurrogate, erload:System.Char.IsNumber, erload:System.Char.IsPunctuation, erload:System.Char.IsSeparator, erload:System.Char.IsSurrogate, erload:System.Char.IsSurrogatePair, erload:System.Char.IsSymbol, erload:System.Char.IsUpper, and erload:System.Char.IsWhiteSpace
|Convert a char object that represents a number to a numeric value type|
|Convert a character in a string into a char object|
|Convert a char object to a string object|
|Change the case of a char object|