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

后端 未结 2 520
北恋
北恋 2021-01-19 18:00
Character.digit(char ch, int radix)

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

Is there an equivalent function i

2条回答
  •  青春惊慌失措
    2021-01-19 18:27

    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

提交回复
热议问题