HttpUtility.HtmlDecode 方法

定义

将已对 HTTP 传输进行 HTML 编码的字符串转换为解码的字符串。

若要对 Web 应用程序外部的值进行编码或解码,请使用类 WebUtility

重载

名称 说明
HtmlDecode(String)

将已对 HTTP 传输进行 HTML 编码的字符串转换为解码的字符串。

HtmlDecode(String, TextWriter)

将已 HTML 编码的字符串转换为解码的字符串,并将解码的字符串发送到 TextWriter 输出流。

HtmlDecode(String)

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

将已对 HTTP 传输进行 HTML 编码的字符串转换为解码的字符串。

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

参数

s
String

要解码的字符串。

返回

解码的字符串。

示例

下面的代码示例演示HtmlEncode了类的HtmlDecodeHttpUtility方法。 输入字符串使用 HtmlEncode 该方法进行编码。 然后,使用 HtmlDecode 该方法解码获取的编码字符串。

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

注解

如果在 HTTP 流中传递空白和标点符号等字符,则它们可能会在接收端被误解。 HTML 编码将 HTML 中不允许的字符转换为字符实体等效项;HTML 解码将反转编码。 例如,在文本块中嵌入时,字符 < 和 > 编码为 &lt;&gt; HTTP 传输。

若要对 Web 应用程序外部的值进行编码或解码,请使用类 WebUtility

另请参阅

适用于

HtmlDecode(String, TextWriter)

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

将已 HTML 编码的字符串转换为解码的字符串,并将解码的字符串发送到 TextWriter 输出流。

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)

参数

s
String

要解码的字符串。

output
TextWriter

TextWriter输出流。

注解

如果在 HTTP 流中传递空白和标点符号等字符,则它们可能会在接收端被误解。 HTML 编码将 HTML 中不允许的字符转换为字符实体等效项;HTML 解码将反转编码。 例如,在文本块中嵌入时,字符 < 和 > 编码为 &lt;&gt; HTTP 传输。

若要对 Web 应用程序外部的值进行编码或解码,请使用类 WebUtility

另请参阅

适用于