33

我有从 xml 模板传入的字符,例如:

& > 

框架中是否存在通用函数来用它们的正常等价物替换它们?

4

3 回答 3

61

你想使用HttpUtility.HtmlDecode.:

将已为 HTTP 传输进行 HTML 编码的字符串转换为已解码的字符串。

于 2010-04-27T11:26:37.347 回答
4

也许这有帮助:WebUtility.HtmlDecode("");

于 2014-12-08T20:33:54.263 回答
4

有时,文本的某些部分已被双重编码。

例如:"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
}
于 2018-10-29T19:54:38.070 回答