Uri.HexEscape(Char)方法用于将指定字符转换为等效的十六进制。
Syntax: public static string HexEscape (char character);
Here, it takes the character to convert to hexadecimal representation.
Return Value: This method returns the hexadecimal representation of the specified character.
Exception: This method throws ArgumentOutOfRangeException if character is greater than 255.
下面的程序说明了Uri.HexEscape(Char)方法的用法:
例子:
// C# program to demonstrate the
// Uri.HexEscape() Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing address1
char ch = 'c';
// Converting the specified character
// into its hexadecimal equivalent
// using HexEscape() method
string value = Uri.HexEscape(ch);
// Displaying the result
Console.WriteLine("Hexadecimal Equivalent is: {0}", value);
}
}
输出:
Hexadecimal Equivalent is: %63
注意:实际无法使用大于255的字符。
参考:
- https://docs.microsoft.com/zh-cn/dotnet/api/system.uri.hexescape?view=netstandard-2.1