The System.Char class has a large number of static methods that serve as utility methods for getting information about individual characters.
Here are some examples:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
| char c1 = '2' ; double d1 = char .GetNumericValue(c1); // Convert '2' to 2.0 UnicodeCategory cat = char .GetUnicodeCategory( 'a' ); // LowercaseLetter cat = char .GetUnicodeCategory( '+' ); // MathSymbol cat = char .GetUnicodeCategory( '6' ); // DecimalDigitNumber // Check for control characters bool isCtrl = char .IsControl( 'a' ); // false isCtrl = char .IsControl( '\t' ); // true // Check for digits bool isDigit = char .IsDigit( 'a' ); // false isDigit = char .IsDigit( '3' ); // true // Check for letters bool isLetter = char .IsLetter( '%' ); // false isLetter = char .IsLetter( 'P' ); // true isLetter = char .IsLetter( 'ǽ' ); // true bool lord = char .IsLetterOrDigit( 'j' ); // true // Check for lower/upper case bool low = char .IsLower( 'j' ); // true low = char .IsLower( 'Y' ); // false bool upper = char .IsUpper( 'Ǻ' ); // true // Check for numbers bool isnum = char .IsNumber( '4' ); // true isnum = char .IsNumber( '௧' ); // true isnum = char .IsNumber( 'X' ); // false // Other bool ispunc = char .IsPunctuation( '?' ); // true bool issep = char .IsSeparator( ' ' ); // true bool issymbol = char .IsSymbol( '$' ); // true // Unicode bool issur = char .IsSurrogate( '\xd840' ); // true bool islow = char .IsLowSurrogate( '\xd840' ); // false bool ishigh = char .IsHighSurrogate( '\xd840' ); // true // Conversion char upp = char .ToUpper( 'a' ); // A char lower = char .ToLower( 'a' ); // a lower = char .ToLower( 'Y' ); // y |