
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Determining Whether a Character Is Within a Specified Range
|
37
The following code example determines whether the fifth character (the
charPosition parameter is zero-based) in the string is a digit:
if (GetCharKind("abcdefg", 4) == CharKind.Digit) {...}
In Version 2.0 of the .NET Framework, a few extra Is* functions were added to aug-
ment the existing methods. If the character in question is a letter (i.e., the
IsLetter
method returns true), you can determine if the letter is uppercase or lowercase by
using the methods in Table 2-2.
If the character in question is a surrogate (i.e., the
IsSurrogate method returns true),
you can use the methods in Table 2-3 to get more information on the surrogate
character.
In addition to these surrogate methods, an additional method,
IsSurrogatePair,
returns
true only if two characters create a surrogate pair—that is, one character is a
high surrogate and one character is a low surrogate.
The final addition to this group of methods is the
IsLetterOrDigit method, which
returns
true only if the character in question is either a letter or a digit. To deter-
mine if the character is either a letter or a digit, use the
IsLetter and IsDigit
methods.
See Also
See the “Char Structure” topic in the MSDN documentation.
2.2 Determining Whether a Character Is Within
a Specified ...