asp.net.ph

HttpUtility.HtmlDecode Method

System.Web Namespace   HttpUtility Class


Converts a string that has been HTML-encoded for HTTP transmission into a decoded string.

Overload List

1. Converts a string that has been HTML-encoded for HTTP transmission into a decoded string.

2. Converts a string that has been HTML-encoded into a decoded string, and sends the decoded string to a TextWriter output stream.


Example

The following example demonstrates the HtmlEncode and HtmlDecode methods of the HttpUtility class. The input string is taken from user and encoded using the HtmlEncode method.The encoded string thus obtained is then decoded using the HtmlDecode method.

NOTE: This example shows how to use one of the overloaded versions of HtmlDecode. For other examples that might be available, see the individual overload topics.

[ VB ]
Imports System
Imports System.Web
Imports System.IO

Class myNewClass
   Public Shared Sub Main ( ) 
      Dim myString As String
      Response.Write ( "Enter a string having '&' or '""'  in it: " ) 
      myString = Console.ReadLine ( ) 
      Dim myEncodedString As String
      ' Encode the string.
      myEncodedString = HttpUtility.HtmlEncode ( myString ) 
      Response.Write ( "HTML Encoded string is " + myEncodedString ) 
      Dim myWriter As New StringWriter ( ) 
      ' Decode the encoded string.
      HttpUtility.HtmlDecode ( myEncodedString, myWriter ) 
      Console.Write ( "Decoded string of the above encoded string is " &_
         myWriter.ToString ( ) ) 
   End Sub
End Class


[ C# ]
using System;
using System.Web;
using System.IO;

class myNewClass {
   public static void Main ( ) {
      String myString;
      Response.Write ( "Enter a string having '&' or '\"'  in it: " );
      myString=Console.ReadLine ( );
      String myEncodedString;
      // Encode the string.
      myEncodedString = HttpUtility.HtmlEncode ( myString );
      Response.Write ( "HTML Encoded string is "+myEncodedString );
      StringWriter myWriter = new StringWriter ( );
      // Decode the encoded string.
      HttpUtility.HtmlDecode ( myEncodedString, myWriter );
      Console.Write ( "Decoded string of the above encoded string is " +
         myWriter.ToString ( ) );
   }
}
See Also

HttpUtility Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph