在ASP.NET中解码HTML中的unicode chracters

时间:2011-04-17 15:38:22

标签: asp.net html

我有一个表示HTML块的字符串。所有unicode字符都被编码。因此在插入数据库时​​需要很多空间。 例如:<p>thích</p>保存为<p>th&iacute;ch</p> 如何解码那些unicode字符?我不能使用HttpUtility.HtmlDecode,因为它会解码一些其他字符,如&gt;或者&lt;同样,我仍然希望它被编码。

1 个答案:

答案 0 :(得分:0)

如何手动重新编码非unicode特定字符?

Server.HtmlDecode(str).Replace("<","&lt;")
                      .Replace(">","&gt;")
                      .Replace("&","&amp;")
                      .Replace("\"","&quot;")
                      .Replace("\'","&#39;")