[ACCEPTED]-Unescape an escaped url in c#-escaping

Accepted answer
Score: 15

& is an HTML entity and is used when text 23 is encoded into HTML because you have to 22 "escape" the & that has a special meaning 21 in HTML. Apparently, this escaping mechanism 20 was used on the URL presumably because it 19 is used in some HTML for instance in a link. I'm 18 not sure why you want to decode it because 17 the browser will do the proper decoding 16 when the link is clicked. But anyway, to 15 revert it you can use HttpUtility.HtmlDecode in the System.Web namespace:

var encoded = "http://www.someurl.com/profile.php?mode=register&agreed=true";
var decoded = HttpUtility.HtmlDecode(encoded);

The 14 value of decoded is:


Another form of encoding/decoding 13 used is URL encoding. This is used to be 12 able to include special characters in parts 11 of the URL. For instance the characters 10 /, ? and & have a special meaning in a URL. If 9 you need to include any of these characters 8 in a say a query parameter you will have 7 to URL encode the parameter to not mess 6 up the URL. Here is an example of an URL 5 where URL escaping has been used:


The company 4 name Barnes & Noble was encoded as Barnes+%26+Noble. If the & hadn't been 3 escaped the URL would have contained not 2 one but two query parameters because & is 1 used as a delimiter between query parameters.

Score: 1

not sure why but decode from @Martin's answer 4 doesn't work in my case (filename in my 3 case is "%D1%8D%D1%84%D1%84%D0%B5%D0%BA%D1%82%D0%B8%D0%BD%D0%BE%D0%B2%D1%81%D1%82%D1%8C%20%D0%BF%D1%80%D0%BE%D0%B4%D0%B0%D0%B6%202020%20(1)-8.xml").

For 2 me works method - https://docs.microsoft.com/en-us/dotnet/api/system.uri.unescape?view=netcore-3.1 .

Be aware that this 1 is obsolete.

More Related questions