SecurityElement.Escape(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將字串中無效的 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)
End If
備註
使用此方法先替換字串中的無效字元,再使用字串。SecurityElement 若在 a SecurityElement 中使用無效字元且未成功逃脫,則會拋出 an ArgumentException 。
下表顯示無效的 XML 字元及其跳脫的對應字元。
| 無效的 XML 字元 | 取代為 |
|---|---|
< |
< |
> |
> |
" |
" |
' |
' |
& |
& |