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);
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.

傳回

String

編碼字串。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. 使用具有單引號屬性的方法時,可能會發生安全性問題 HtmlAttributeEncodeSecurity 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);
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. 它比方法快得多 HtmlEncodeIt is considerably faster than the HtmlEncode method.

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

適用於