Edit

Share via


Uri.IsHexEncoding(String, Int32) Method

Definition

Determines whether a character in a string is hexadecimal encoded.

C#
public static bool IsHexEncoding(string pattern, int index);

Parameters

pattern
String

The string to check.

index
Int32

The location in pattern to check for hexadecimal encoding.

Returns

true if pattern is hexadecimal encoded at the specified location; otherwise, false.

Examples

The following code example determines whether a character is hexadecimal encoded and, if so, writes the equivalent character to the console.

C#
string testString = "%75";
int index = 0;
if (Uri.IsHexEncoding(testString, index))
     Console.WriteLine("The character is {0}", Uri.HexUnescape(testString, ref index));
else
     Console.WriteLine("The character is not hexadecimal encoded");

Remarks

The IsHexEncoding method checks for hexadecimal encoding that follows the pattern "%hexhex" in a string, where "hex" is a digit from 0 to 9 or a letter from A-F (case-insensitive).

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1