WebUtility.HtmlEncode 方法

定义

将字符串转换为 HTML 编码字符串。

重载

HtmlEncode(String)

将字符串转换为 HTML 编码字符串。

HtmlEncode(String, TextWriter)

将字符串转换为 HTML 编码的字符串,并以 TextWriter 输出流的形式返回输出。

HtmlEncode(String)

将字符串转换为 HTML 编码字符串。

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

参数

value
String

要编码的字符串。

返回

已编码的字符串。

注解

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

value如果 参数为 null,则返回的编码字符串为 nullvalue如果 参数为空字符串,则返回的编码字符串为空字符串。

另请参阅

适用于

HtmlEncode(String, TextWriter)

将字符串转换为 HTML 编码的字符串,并以 TextWriter 输出流的形式返回输出。

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

参数

value
String

要编码的字符串。

output
TextWriter

TextWriter 输出流。

例外

如果 output 参数不为 null,则 value 参数不能为 null

注解

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

另请参阅

适用于