Uri.FromHex(Char) Uri.FromHex(Char) Uri.FromHex(Char) Uri.FromHex(Char) Method

定义

获取十六进制数字的十进制值。Gets the decimal value of a hexadecimal digit.

public:
 static int FromHex(char digit);
public static int FromHex (char digit);
static member FromHex : char -> int
Public Shared Function FromHex (digit As Char) As Integer

参数

digit
Char Char Char Char

要转换的十六进制数字(0-9、a-f、A-F)。The hexadecimal digit (0-9, a-f, A-F) to convert.

返回

一个 Int32 值,包含与指定的十六进制数字对应的介于 0 到 15 之间的数字。An Int32 value that contains a number from 0 to 15 that corresponds to the specified hexadecimal digit.

异常

digit 不是有效的十六进制数字(0-9、a-f、A-F)。digit is not a valid hexadecimal digit (0-9, a-f, A-F).

示例

下面的示例确定字符是否为十六进制字符, 如果为, 则将相应的十进制值写入控制台。The following example determines whether a character is a hexadecimal character and, if it is, writes the corresponding decimal value to the console.

char testChar = 'e';
if ( Uri::IsHexDigit( testChar ) == true )
{
   Console::WriteLine( "'{0}' is the hexadecimal representation of {1}",
      testChar, Uri::FromHex( testChar ) );
}
else
{
   Console::WriteLine( "'{0}' is not a hex character", testChar );
}

String^ returnString = Uri::HexEscape( testChar );
Console::WriteLine( "The hexadecimal value of '{0}' is {1}", testChar, returnString );
char  testChar = 'e';
if (Uri.IsHexDigit(testChar) == true)
    Console.WriteLine("'{0}' is the hexadecimal representation of {1}", testChar, Uri.FromHex(testChar));
else 
    Console.WriteLine("'{0}' is not a hexadecimal character", testChar);

string returnString = Uri.HexEscape(testChar);
Console.WriteLine("The hexadecimal value of '{0}' is {1}", testChar, returnString);
Dim testChar As Char = "e"c
If Uri.IsHexDigit(testChar) = True Then
    Console.WriteLine("'{0}' is the hexadecimal representation of {1}", testChar, Uri.FromHex(testChar))
Else
    Console.WriteLine("'{0}' is not a hexadecimal character", testChar)
End If 
Dim returnString As String = Uri.HexEscape(testChar)
Console.WriteLine("The hexadecimal value of '{0}' is {1}", testChar, returnString)

注解

FromHex方法将表示十六进制数字的字符 (0-9、a-f、a-f) 转换为其十进制值 (0 到 15)。The FromHex method converts a character representing a hexadecimal digit (0-9, a-f, A-F) to its decimal value (0 to 15). 如果digit不是有效的十六进制数字ArgumentException , 则会引发异常。If digit is not a valid hexadecimal digit, an ArgumentException exception is thrown.

适用于