SecurityElement.Escape(String) 方法

定義

將字串中無效的 XML 字元以它們的相等有效 XML 字元來取代。

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

參數

str
String

要逸出無效字元的字串。

傳回

無效字元被取代後的輸入字串。

範例

下列程式碼示範如何使用 Escape 方法來取代字串中不正確 XML 字元與其有效的 XML 對等專案。 此程式碼範例是針對 類別提供的較大範例的 SecurityElement 一部分。

tagText = SecurityElement::Escape( tagText );
tagText = SecurityElement.Escape(tagText);
    tagText = SecurityElement.Escape(tagText)
End If

備註

使用這個方法,在 中使用 中的字串之前,先取代字串中的 SecurityElement 無效字元。 如果在 不使用 SecurityElement 逸出的情況下使用不正確字元, ArgumentException 則會擲回 。

下表顯示不正確 XML 字元及其逸出對等專案。

不正確 XML 字元 取代為
< &lt;
> &gt;
" &quot;
' &apos;
& &amp;

適用於