HttpUtility.HtmlAttributeEncode 方法

定義

以最簡化的方式將字串轉換為 HTML 編碼的字串。Minimally converts a string into an HTML-encoded string.

多載

HtmlAttributeEncode(String)

最低限度將字串轉換成 HTML 編碼字串。Minimally converts a string to an HTML-encoded string.

HtmlAttributeEncode(String, TextWriter)

以最簡化的方式將字串轉換為 HTML 編碼的字串,並將編碼的字串傳送至 TextWriter 輸出資料流。Minimally converts a string into an HTML-encoded string and sends the encoded string to a TextWriter output stream.

HtmlAttributeEncode(String)

最低限度將字串轉換成 HTML 編碼字串。Minimally converts a string to an HTML-encoded string.

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

參數

s
String

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

傳回

編碼字串。An encoded string.

備註

方法HtmlAttributeEncode會將適用于插入的字元編碼成 HTML 屬性值。The HtmlAttributeEncode method encodes characters appropriate for insertion into an HTML attribute value.

HtmlAttributeEncode方法的字串結果應該僅用於雙引號屬性。The string result from the HtmlAttributeEncode method should be used only for double-quoted attributes. 使用方法搭配單加引號的HtmlAttributeEncode屬性時,可能會發生安全性問題。Security issues might arise when using the HtmlAttributeEncode method with single-quoted attributes.

另請參閱

HtmlAttributeEncode(String, TextWriter)

以最簡化的方式將字串轉換為 HTML 編碼的字串,並將編碼的字串傳送至 TextWriter 輸出資料流。Minimally converts a string into an HTML-encoded string and sends the encoded string to a TextWriter output stream.

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

參數

s
String

要編碼的字串The string to encode

output
TextWriter

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

備註

HtmlAttributeEncode方法只會將雙引號(")、單引號(')、符號(&)和左角括弧(<)轉換為對等的字元實體。The HtmlAttributeEncode method converts only double quotation marks ("), single quotation marks ('), ampersands (&), and left angle brackets (<) to equivalent character entities. 速度會比HtmlEncode方法快得多。It is considerably faster than the HtmlEncode method.

HtmlAttributeEncode方法的字串結果應該僅用於雙引號屬性。The string result from the HtmlAttributeEncode method should be used only for double-quoted attributes. 使用方法搭配單加引號的HtmlAttributeEncode屬性時,可能會發生安全性問題。Security issues might arise when using the HtmlAttributeEncode method with single-quoted attributes.

另請參閱

適用於