tags:

views:

826

answers:

5

.Net's Server.HTMLEncode() is the very helpful function that takes an HTML string and replaces special characters with their entity equivalents - "<" becomes &lt ; and so forth.

Is there a (built-in) function that does the reverse? There doesn't seem to be, and I am incredulous. While I could certainly write my own (and have in the past) Server.HTMLEncode has all kinds of cool handling for different string encodings and high-level unicode characters that I would really not have crash my hand-rolled decoder in a year's time.

What do other people do when they need the plain HTML back?

Update: To answer the first batch of questions, I present the MSDN article on the Server object, which has Encode but no Decode... I'm as amazed as anyone.

Update2: as several alert readers have pointed out, the docs I was looking at were for classic ASP, not ASP.Net. Thanks guys, that's an important MSDN safety tip.

+10  A: 

Server.HtmlDecode ....

Sergio
+4  A: 

You didn't see a HtmlDecode in the same place you found the HtmlEncode?

Cristian Libardo
A: 

HttpServerUtility.HtmlDecode

A: 

Ah, MSDN, I love you.

There IS a Server.HTMLDecode() method, the documentation for the server object just doesn't mention that it exists.

Thanks, everybody!

Electrons_Ahoy
+3  A: 

You're looking at the wrong docs. Check this out:

http://msdn.microsoft.com/en-us/library/system.web.httpserverutility_methods.aspx http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.htmlencode.aspx http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.htmldecode.aspx

Michael Haren
Oh SNAP! There we go. Thank you very, very much. I KNEW that had to be in there somewhere.
Electrons_Ahoy