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:

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

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }  
}

chevron_right


Output:

Hexadecimal character: p

Example 2:

C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }  
}

chevron_right


Output:

Hexadecimal character: 7



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.