Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something like java's Character.digit(char ch, int radix) in c#?

Tags:

java

c#

character

Character.digit(char ch, int radix)

Returns the numeric value of the character ch in the specified radix.

Is there an equivalent function in c#?

like image 556
kitsune Avatar asked Jun 20 '09 13:06

kitsune


1 Answers

I don't know of a direct equivalent
The closest match I can find is

Convert.ToInt32(string s, int baseFrom);  

So you could convert your char to string then pass it in to the above function to get the int32 or Int16 or Byte or however you want to handle it :

char c = 'F';

int digit = Convert.ToInt32(c.ToString(),16);

Note - Convert will throw a FormatException if the char isn't a digit

like image 111
zebrabox Avatar answered Sep 27 '22 22:09

zebrabox