Uri.HexEscape(Char)方法用於將指定字符轉換為等效的十六進製。
用法: public static string HexEscape (char character);
Here, it takes the character to convert to hexadecimal representation.
返回值:此方法返回指定字符的十六進製表示形式。
異常:如果字符大於255,則此方法引發ArgumentOutOfRangeException。
以下示例程序旨在說明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的字符實際上是不可能的。
參考:
相關用法
- C# DateTimeOffset.Add()用法及代碼示例
- C# String.Contains()用法及代碼示例
- C# Math.Sin()用法及代碼示例
- C# Math.Cos()用法及代碼示例
- C# Dictionary.Add()用法及代碼示例
- C# Math.Tan()用法及代碼示例
- C# Math.Abs()方法用法及代碼示例
- C# Math.Exp()用法及代碼示例
- C# Math.Abs()函數用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 C# | Uri.HexEscape(Char) Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。