C# | Uri.IsHexEncoding() Method
Last Updated :
30 Apr, 2019
Uri.IsHexEncoding(String, Int32) Method is used to check whether a character in a string is hexadecimal encoded or not. This checks for hexadecimal encoding which follows the pattern “%hexhex” in a string, where “hex” is a digit from 0 to 9 or a letter from A-F (case-insensitive).
Syntax: public static bool IsHexEncoding (string pattern, int index);
Parameters:
pattern: It is the string to check.
index: It is the location in pattern to check for hexadecimal encoding.
Return Value: This method returns a Boolean value that is true if pattern is hexadecimal encoded at the specified location otherwise, false.
Below programs illustrate the use of Uri.IsHexEncoding(String, Int32) Method:
Example 1:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
string pattern = "%75" ;
int index = 1;
bool value = Uri.IsHexEncoding(pattern, index);
if (value)
Console.WriteLine( "{0}({1}) is a valid " +
"Hexadecimal Encoded" , pattern);
else
Console.WriteLine( "{0} is a valid" +
" Hexadecimal Encoded" , pattern);
}
}
|
Output:
%75 is a valid Hexadecimal Encoded
Example 2:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
get ( "%65" , 1);
get ( "%75" , 0);
get ( "%55" , 0);
}
public static void get ( string pattern,
int index)
{
bool value = Uri.IsHexEncoding(pattern, index);
if (value)
Console.WriteLine( "{0} is a valid" +
" Hexadecimal Encoded" , pattern);
else
Console.WriteLine( "{0} is a not valid" +
" Hexadecimal Encoded" , pattern);
}
}
|
Output:
%65 is a not valid Hexadecimal Encoded
%75 is a valid Hexadecimal Encoded
%55 is a valid Hexadecimal Encoded
Reference:
Share your thoughts in the comments
Please Login to comment...