Export (0) Print
Expand All

HttpUtility.HtmlDecode Method

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

Overload List

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

[Visual Basic] Overloads Public Shared Function HtmlDecode(String) As String
[C#] public static string HtmlDecode(string);
[C++] public: static String* HtmlDecode(String*);
[JScript] public static function HtmlDecode(String) : String;

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

[Visual Basic] Overloads Public Shared Sub HtmlDecode(String, TextWriter)
[C#] public static void HtmlDecode(string, TextWriter);
[C++] public: static void HtmlDecode(String*, TextWriter*);
[JScript] public static function HtmlDecode(String, TextWriter);

Example

[Visual Basic, C#, C++] 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.

[Visual Basic, C#, C++] 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.
[Visual Basic] 
Imports System
Imports System.Web
Imports System.IO

Class MyNewClass
   Public Shared Sub Main()
      Dim myString As String
      Console.WriteLine("Enter a string having '&' or '""'  in it: ")
      myString = Console.ReadLine()
      Dim myEncodedString As String
      ' Encode the string.
      myEncodedString = HttpUtility.HtmlEncode(myString)
      Console.WriteLine("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 'Main
End Class 'MyNewClass

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

   class MyNewClass
   {
      public static void Main()
      {
         String myString;
         Console.WriteLine("Enter a string having '&' or '\"'  in it: ");
         myString=Console.ReadLine();
         String myEncodedString;
         // Encode the string.
         myEncodedString = HttpUtility.HtmlEncode(myString);
         Console.WriteLine("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());
      }
   }

[C++] 
#using <mscorlib.dll>
#using <System.dll>
#using <System.Web.dll>
using namespace System;
using namespace System::Web;
using namespace System::IO;

int main()
{
   String * myString;
   Console::WriteLine(S"Enter a string having '&' or '\"'  in it: ");
   myString=Console::ReadLine();
   String * myEncodedString;
   // Encode the string.
   myEncodedString = HttpUtility::HtmlEncode(myString);
   Console::WriteLine("HTML Encoded String* is S {0}", myEncodedString);
   StringWriter* myWriter = new StringWriter();
   // Decode the encoded String.
   HttpUtility::HtmlDecode(myEncodedString, myWriter);
   Console::Write("Decoded string of the above encoded string is {0}", myWriter);
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

HttpUtility Class | HttpUtility Members | System.Web Namespace

Show:
© 2014 Microsoft