Uri.IsHexEncoding(String,Int32)方法用於檢查字符串中的字符是否用十六進製編碼。這將檢查字符串中遵循模式“%hexhex”的十六進製編碼,其中“hex”是從0到9的數字或A-F(大小寫敏感)的字母。
用法: public static bool IsHexEncoding (string pattern, int index);
參數:
pattern:這是要檢查的字符串。
index:這是樣式中檢查十六進製編碼的位置。
返回值:如果模式在指定位置以十六進製編碼,則此方法返回一個布爾值,該值為true,否則為false。
以下示例程序旨在說明Uri.IsHexEncoding(String,Int32)方法的用法:
示例1:
// C# program to demonstrate the
// Uri.IsHexEncoding(String,
// Int32) Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing pattern
string pattern = "%75";
// Declaring and initializing index
int index = 1;
// Validating the Character in the String
// using IsHexEncoding(String, Int32) method
bool value = Uri.IsHexEncoding(pattern, index);
// Displaying the result
if (value)
Console.WriteLine("{0}({1}) is a valid "+
"Hexadecimal Encoded", pattern);
else
Console.WriteLine("{0} is a valid"+
" Hexadecimal Encoded", pattern);
}
}
輸出:
%75 is a valid Hexadecimal Encoded
示例2:
// C# program to demonstrate the
// Uri.IsHexEncoding(String,
// Int32) Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// calling get() method
get("%65", 1);
get("%75", 0);
get("%55", 0);
}
// defining get() method
public static void get(string pattern,
int index)
{
// Validating the Character in the String
// using IsHexEncoding(String, Int32) method
bool value = Uri.IsHexEncoding(pattern, index);
// Displaying the result
if (value)
Console.WriteLine("{0} is a valid"+
" Hexadecimal Encoded", pattern);
else
Console.WriteLine("{0} is a not valid"+
" Hexadecimal Encoded", pattern);
}
}
輸出:
%65 is a not valid Hexadecimal Encoded %75 is a valid Hexadecimal Encoded %55 is a valid Hexadecimal Encoded
參考:
相關用法
- 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.IsHexEncoding() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。