Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I decode HTML that was encoded in JS using encodeURIComponent()?

I tried :

string decodedHtml = HttpUtility.HtmlDecode(html); 

Where html is the encoded html. It seems that this does not alter the string at all. The html is still encoded.

like image 410
Nick Avatar asked May 16 '11 20:05

Nick


People also ask

How do I use encodeURIComponent in JavaScript?

The encodeURIComponent() function encodes a URI by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).

How do I decode encodeURI?

1. decodeURI function: The decodeURI() function is used to decode URI generated by encodeURI(). Parameters: This function accepts a single parameter complete_encoded_uri_string which holds the encoded string. Return Value: This function returns the decoded string (original string).

How is HTML decoded?

HTML DECODE: HTML Decoding is an opposite of encoding process. in decoding process, the specially encoded characters are converted back to their original form. it decodes a string that contains HTML numeric character references and returns the decoded string.


2 Answers

string s = System.Uri.UnescapeDataString(html); 
like image 121
Brandon Boone Avatar answered Sep 24 '22 07:09

Brandon Boone


Think you can use this code.

HttpContext.Current.Server.UrlDecode(html) 
like image 36
Binh LE Avatar answered Sep 20 '22 07:09

Binh LE