Uri.IsHexEncoding() Method in C#


The Uri.IsHexEncoding() method in C# determines whether a character in a string is hexadecimal encoded.

Syntax

Following is the syntax −

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

Above, the pattern parameter is the string to check, whereas the index is the location in pattern to check for hexadecimal encoding.

Example

Let us now see an example to implement the Uri.IsHexEncoding() method −

using System;
public class Demo {
   public static void Main(){
      string pattern = "%50";
      bool res = Uri.IsHexEncoding(pattern, 0);
      if (res)
         Console.WriteLine("Valid: Hexadecimal Encoded");
      else
         Console.WriteLine("Invalid: Hexadecimal Encoded");
   }
}

Output

This will produce the following output −

Valid: Hexadecimal Encoded

Example

Let us now see another example to implement the Uri.IsHexEncoding() method:

using System;
public class Demo {
   public static void Main(){
      string pattern = "%60";
      bool res = Uri.IsHexEncoding(pattern, 1);
      if (res)
         Console.WriteLine("Valid: Hexadecimal Encoded");
      else
         Console.WriteLine("Invalid: Hexadecimal Encoded");
   }
}

Output

This will produce the following output −

Invalid: Hexadecimal Encoded

Updated on: 14-Nov-2019

17 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements