Open In App

Uri.HexUnescape() Method in C# with Examples

Last Updated : 08 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • string str – This represents the hexadecimal string.
  • ref int index – This represents location in pattern where the hexadecimal representation of a character begins.

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#




// 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#




// 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


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads