Uri.IsHexDigit(Char) 方法

定義

判斷指定的字元是否為有效的十六進位數字。

public:
 static bool IsHexDigit(char character);
public static bool IsHexDigit (char character);
static member IsHexDigit : char -> bool
Public Shared Function IsHexDigit (character As Char) As Boolean

參數

character
Char

要驗證的字元。

傳回

若字元為有效的十六進位數字,即為 true;否則為 false

範例

下列範例會判斷字元是否為十六進位字元,如果是,則會將對應的十進位值寫入主控台。

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)

備註

十六進位數位是 0 到 9 的數位,以及字母 A-F 或 a-f。

適用於