Uri.IsHexEncoding(String, Int32) 方法

定义

确定字符串中的一个字符是否为十六进制编码。

C#
public static bool IsHexEncoding(string pattern, int index);

参数

pattern
String

要检查的字符串。

index
Int32

检查十六进制编码的 pattern 中的位置。

返回

如果 pattern 在指定位置进行了十六进制编码,则该值为 true;否则为 false

示例

下面的代码示例确定字符是否是十六进制编码的,如果是,则向控制台写入等效字符。

C#
string testString = "%75";
int index = 0;
if (Uri.IsHexEncoding(testString, index))
     Console.WriteLine("The character is {0}", Uri.HexUnescape(testString, ref index));
else
     Console.WriteLine("The character is not hexadecimal encoded");

注解

方法 IsHexEncoding 检查字符串中遵循模式“%hexhex”的十六进制编码,其中“hex”是 0 到 9 之间的数字,或来自 A-F (不区分大小写) 的字母。

适用于

产品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1