WebUtility.HtmlEncode 方法

定義

將字串轉換成 HTML 編碼字串。Converts a string to an HTML-encoded string.

多載

HtmlEncode(String)

將字串轉換成 HTML 編碼字串。Converts a string to an HTML-encoded string.

HtmlEncode(String, TextWriter)

將字串轉換成 HTML 編碼字串,並以 TextWriter 輸出資料流的形式傳回輸出。Converts a string into an HTML-encoded string, and returns the output as a TextWriter stream of output.

HtmlEncode(String)

將字串轉換成 HTML 編碼字串。Converts a string to an HTML-encoded string.

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

要編碼的字串。The string to encode.

傳回

String

編碼字串。An encoded string.

備註

如果在 HTTP 資料流程中傳遞空白和標點符號之類的字元,它們可能會在接收端被誤解。If characters such as blanks and punctuation are passed in an HTTP stream, they might be misinterpreted at the receiving end. HTML 編碼會將 HTML 中不允許的字元轉換為對等的字元實體;HTML 解碼會反轉編碼。HTML encoding converts characters that are not allowed in HTML into character-entity equivalents; HTML decoding reverses the encoding. 例如,內嵌在文字區塊中時,字元 <> 會編碼為 &lt;&gt; HTTP 傳輸。For example, when embedded in a block of text, the characters < and > are encoded as &lt; and &gt; for HTTP transmission.

如果 value 參數為 null ,則傳回的編碼字串為 nullIf the value parameter is null, then the returned encoded string is null. 如果 value 參數是空字串,則傳回的編碼字串會是空字串。If the value parameter is an empty string, then the returned encoded string is an empty string.

另請參閱

適用於

HtmlEncode(String, TextWriter)

將字串轉換成 HTML 編碼字串,並以 TextWriter 輸出資料流的形式傳回輸出。Converts a string into an HTML-encoded string, and returns the output as a TextWriter stream of output.

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

要編碼的字串。The string to encode.

output
TextWriter

TextWriter 輸出資料流。A TextWriter output stream.

例外狀況

如果 output 參數不是 nullvalue 不能為 nullThe output parameter cannot be null if the value parameter is not null.

備註

如果在 HTTP 資料流程中傳遞空白和標點符號之類的字元,它們可能會在接收端被誤解。If characters such as blanks and punctuation are passed in an HTTP stream, they might be misinterpreted at the receiving end. HTML 編碼會將 HTML 中不允許的字元轉換為對等的字元實體;HTML 解碼會反轉編碼。HTML encoding converts characters that are not allowed in HTML into character-entity equivalents; HTML decoding reverses the encoding. 例如,內嵌在文字區塊中時,字元 <> 會編碼為 &lt;&gt; HTTP 傳輸。For example, when embedded in a block of text, the characters < and > are encoded as &lt; and &gt; for HTTP transmission.

另請參閱

適用於