Uri.FromHex(Char) 方法

定义

获取十六进制数字的十进制值。

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

要转换的十六进制数字(0-9、a-f、A-F)。

返回

与指定的十六进制数字对应的介于 0 到 15 之间的数字。

例外

digit 不是有效的十六进制数字(0-9、a-f、A-F)。

示例

以下示例确定某个字符是否为十六进制字符,如果为,则会将相应的十进制值写入控制台。

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);
let testChar = 'e'
if Uri.IsHexDigit testChar then
    printfn $"'{testChar}' is the hexadecimal representation of {Uri.FromHex testChar}"
else
    printfn $"'{testChar}' is not a hexadecimal character"

let returnString = Uri.HexEscape testChar
printfn $"The hexadecimal value of '{testChar}' is {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) 。 如果 digit 不是有效的十六进制数字, ArgumentException 则会引发异常。

适用于