편집

다음을 통해 공유


HttpUtility.HtmlDecode Method

Definition

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

To encode or decode values outside of a web application, use the WebUtility class.

Overloads

HtmlDecode(String)

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

HtmlDecode(String, TextWriter)

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

HtmlDecode(String)

Source:
HttpUtility.cs
Source:
HttpUtility.cs
Source:
HttpUtility.cs

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

public:
 static System::String ^ HtmlDecode(System::String ^ s);
public static string? HtmlDecode (string? s);
public static string HtmlDecode (string s);
static member HtmlDecode : string -> string
Public Shared Function HtmlDecode (s As String) As String

Parameters

s
String

The string to decode.

Returns

A decoded string.

Examples

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

using System;
using System.Web;
using System.IO;

class MyNewClass
{
    public static void Main()
    {
        Console.WriteLine("Enter a string having '&', '<', '>' or '\"' in it: ");
        string myString = Console.ReadLine();

        // Encode the string.
        string myEncodedString = HttpUtility.HtmlEncode(myString);

        Console.WriteLine($"HTML Encoded string is: {myEncodedString}");
        StringWriter myWriter = new StringWriter();

        // Decode the encoded string.
        HttpUtility.HtmlDecode(myEncodedString, myWriter);

        string myDecodedString = myWriter.ToString();
        Console.Write($"Decoded string of the above encoded string is: {myDecodedString}");
    }
}
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
End Class

Remarks

If characters such as blanks and punctuation are passed in an HTTP stream, they might be misinterpreted at the receiving end. HTML encoding converts characters that are not allowed in HTML into character-entity equivalents; HTML decoding reverses the encoding. For example, when embedded in a block of text, the characters < and > are encoded as &lt; and &gt; for HTTP transmission.

To encode or decode values outside of a web application, use the WebUtility class.

See also

Applies to

HtmlDecode(String, TextWriter)

Source:
HttpUtility.cs
Source:
HttpUtility.cs
Source:
HttpUtility.cs

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

public:
 static void HtmlDecode(System::String ^ s, System::IO::TextWriter ^ output);
public static void HtmlDecode (string? s, System.IO.TextWriter output);
public static void HtmlDecode (string s, System.IO.TextWriter output);
static member HtmlDecode : string * System.IO.TextWriter -> unit
Public Shared Sub HtmlDecode (s As String, output As TextWriter)

Parameters

s
String

The string to decode.

output
TextWriter

A TextWriter stream of output.

Remarks

If characters such as blanks and punctuation are passed in an HTTP stream, they might be misinterpreted at the receiving end. HTML encoding converts characters that are not allowed in HTML into character-entity equivalents; HTML decoding reverses the encoding. For example, when embedded in a block of text, the characters < and > are encoded as &lt; and &gt; for HTTP transmission.

To encode or decode values outside of a web application, use the WebUtility class.

See also

Applies to