Open In App

Uri.HexUnescape() Method in C# with Examples

Uri.HexUnescape() method is used to convert a specified hexadecimal representation of a character to the character.

Syntax:



public static char HexUnescape (string pattern, ref int index);

Parameters:

Return value: This method returns the character represented by the hexadecimal encoding at position index. If the character at index is not hexadecimal encoded, the character at index is returned. The value of index is incremented to point to the character following the one returned.



Exception: This method throws ArgumentOutOfRangeException if index is less than 0 or greater than or equal to the number of characters.
 

Example 1: 




// C# program to demonstrate the  
// Uri.HexUnescape() method  
using System;   
      
class GFG {  
      
     // Main Method  
    public static void Main()  
    {  
        // Declaring and initializing 
        string str = "%70";
        char retChar;
        int index = 0;
          
        // using HexUnescape() method  
        retChar = Uri.HexUnescape(str,ref index);
          
        Console.WriteLine("Hexadecimal character: "+retChar);
    }  
}

Output:

Hexadecimal character: p

Example 2:




// C# program to demonstrate the  
// Uri.HexUnescape() method  
using System;   
      
class GFG {  
      
     // Main Method  
    public static void Main()  
    {  
        // Declaring and initializing 
        string str = Convert.ToString(123, 16);
        char retChar;
        int index =    0;
          
        // using HexUnescape() method  
        retChar = Uri.HexUnescape(str,ref index);
          
        Console.WriteLine("Hexadecimal character: "+retChar);
    }  
}

Output:

Hexadecimal character: 7

Article Tags :
C#