Uri.IsHexDigit(Char)方法用于确定指定字符是否为有效的十六进制数字。十六进制数字是数字0到9以及字母AF或af 。
Syntax: public static bool IsHexDigit (char character);
Here, it takes the character to validate.
Return Value: This method returns true if the character is a valid hexadecimal digit otherwise, false.
下面的程序说明了Uri.IsHexDigit(Char)方法的用法:
范例1:
// C# program to demonstrate the
// Uri.IsHexDigit(Char) Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing address1
char ch = 'a';
// Validating the Character
// using IsHexDigit(Char) method
bool value = Uri.IsHexDigit(ch);
// Displaying the result
if (value)
Console.WriteLine("{0} is a valid Hexadecimal Digit", ch);
else
Console.WriteLine("{0} is a not valid Hexadecimal Digit", ch);
}
}
输出:
a is a valid Hexadecimal Digit
范例2:
// C# program to demonstrate the
// Uri.IsHexDigit(Char) Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// calling get() method
get('a');
get('.');
get('1');
}
// defining get() method
public static void get(char ch)
{
// Validating the Character
// using IsHexDigit(Char) method
bool value = Uri.IsHexDigit(ch);
// Displaying the result
if (value)
Console.WriteLine("{0} is a valid Hexadecimal Digit", ch);
else
Console.WriteLine("{0} is a not valid Hexadecimal Digit", ch);
}
}
输出:
a is a valid Hexadecimal Digit
. is a not valid Hexadecimal Digit
1 is a valid Hexadecimal Digit
参考:
- https://docs.microsoft.com/zh-cn/dotnet/api/system.uri.ishexdigit?view=netstandard-2.1