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无效字符。 如果在不使用转义的情况下使用 SecurityElement 无效字符,则会引发一个 ArgumentException 。
下表显示了无效的 XML 字符及其转义等效项。
| 无效的 XML 字符 | 替换为 |
|---|---|
< |
< |
> |
> |
" |
" |
' |
' |
& |
& |