Useful static methods on the Char class

Whilst read­ing through the answers for this ques­tion on Stack­Over­flow, I came across the IsDig­it and IsNum­ber meth­ods on the Char class. And look­ing at the Char class in more detail there are many more use­ful meth­ods on the Char class which I didn’t realise was there before, such as:

IsDig­it checks if a char­ac­ter is a radix-10 dig­it, i.e. 0–9.

IsNum­ber checks if a char­ac­ter can be cat­e­go­rized as a num­ber, includ­ing dig­its, char­ac­ters, frac­tions, sub­scripts, cur­ren­cy numer­a­tors, etc.

Get­Nu­mer­ic­Val­ue con­verts a char­ac­ter to a dou­ble.

GetU­ni­code­Cat­e­go­ry cat­e­go­rizes a char­ac­ter into a group iden­ti­fied by one of the Uni­code­Cat­e­go­ry enum. This is an inter­est­ing method as it allows you to check whether a giv­en char­ac­ter is a cur­ren­cy sym­bol or maths sym­bol for instance:

char.GetUnicodeCategory('+').Dump();  // UnicodeCategory.MathSymbol
char.GetUnicodeCategory('-').Dump();  // UnicodeCategory.DashPunctuation
char.GetUnicodeCategory('{').Dump();  // UnicodeCategory.OpenPunctuation
char.GetUnicodeCategory('$').Dump();  // UnicodeCategory.CurrencySymbol
char.GetUnicodeCategory('}').Dump();  // UnicodeCategory.ClosePunctuation

IsCon­trol checks whether a char­ac­ter is a con­trol char­ac­ter.

IsLet­ter checks whether a char­ac­ter is a uni­code let­ter.

IsLet­terOrDig­it checks whether a char­ac­ter is a let­ter or a dec­i­mal dig­it.

IsLow­er and IsUp­per checks whether a char­ac­ter is low­er or upper case let­ter.

IsWhite­Space checks if a char­ac­ter is a white space.

What’s even bet­ter, each of the meth­ods are over­loaded so that you can pass in the char to test or a string and an accom­pa­ny­ing int to spec­i­fy the posi­tion of the char in the string, e.g. IsDigit(char) and IsDigit(string, int).

Liked this post? Why not support me on Patreon and help me get rid of the ads!