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))
    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 则会引发异常。

适用于