我有从 xml 模板传入的字符,例如:
& >
框架中是否存在通用函数来用它们的正常等价物替换它们?
你想使用HttpUtility.HtmlDecode
.:
将已为 HTTP 传输进行 HTML 编码的字符串转换为已解码的字符串。
也许这有帮助:WebUtility.HtmlDecode("");
有时,文本的某些部分已被双重编码。
例如:"Lorem Ipsum
    - Blah"
这可能有助于:
public static string RecursiveHtmlDecode(string str) {
if (string.IsNullOrWhiteSpace(str)) return str;
var tmp = HttpUtility.HtmlDecode(str);
while (tmp != str)
{
str = tmp;
tmp = HttpUtility.HtmlDecode(str);
}
return str; //completely decoded string
}