C# 中的 Uri.IsHexEncoding() 方法
csharpserver side programmingprogramming更新于 2025/9/23 10:52:17
C# 中的 Uri.IsHexEncoding() 方法用于判断字符串中的字符是否为十六进制编码。
语法
以下是语法 −
public static bool IsHexEncoding (string pattern, int index);
以上代码中,pattern 参数是需要检查的字符串,而 index 参数是 pattern 中需要检查十六进制编码的位置。
示例
现在让我们看一个实现 Uri.IsHexEncoding() 方法 − 的示例
using System;
public class Demo {
public static void Main(){
string pattern = "%50";
bool res = Uri.IsHexEncoding(pattern, 0);
if (res)
Console.WriteLine("有效:十六进制编码");
else
Console.WriteLine("无效:十六进制编码");
}
}
前>
输出
这将产生以下输出−
有效:十六进制编码
前>
示例
现在让我们看另一个实现 Uri.IsHexEncoding() 方法的示例:
using System;
public class Demo {
public static void Main(){
string pattern = "%60";
bool res = Uri.IsHexEncoding(pattern, 1);
if (res)
Console.WriteLine("Valid: Hexadecimal Encoded");
else
Console.WriteLine("Invalid: Hexadecimal Encoded");
}
}
输出
这将产生以下输出 −
Invalid: Hexadecimal Encoded
相关文章

