Name

HtmlDecode

Synopsis

returnstring = Server.HtmlDecode(s)
Server.HtmlDecode(s,output)

Returns a string in which any HTML information encoded by the HtmlEncode method (described later in this chapter) is decoded back into its standard HTML format.

Parameters

returnstring

A String variable to receive the decoded string from the method.

s

A string variable containing the encoded HTML that the method will decode.

output

An instance of any class derived from the TextWriter class (found in the System.IO namespace) used to capture the decoded string.

Example

The code example declares two string variables, sets the value of StrToDecode to the encoded equivalent of <p>Hello, World!</p>, assigns the return value of the Server.HtmlDecode call to StrToReturn, and then writes the value to the browser using the Message label control:

Sub Page_Load(  )
   Dim StrToDecode As String
   Dim StrToReturn As String
   StrToDecode = "&lt;p&gt;Hello, World!&lt;/p&gt;"
   StrToReturn = Server.HtmlDecode(StrToDecode)
   Message.Text = StrToReturn
End Sub

Notes

This method provides a simple way to undo the effects of calling HtmlEncode on a given string. You can also use it as an educational tool to demonstrate the relationship between various characters used in HTML and ASP (such as the greater-than (>) and less-than (<) symbols) and their encoded equivalents.

When called with only the s argument, this method returns a string. When called with both an s argument and an output argument (such as a StringWriter or HtmlTextWriter ...

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.