共用方式為


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 則會擲回例外狀況。

適用於