删除或转换和放大器;#39;至 (')放大器

2023-09-04 01:00:01 作者:绵延时光等一个答案 〃

我耗时一个API,我注意到,它回来了&放大器;#39;的,而不是一个单引号。因为我不会被显示在HTML这段文字,这将让我的文字看起来奇怪的,当我展示给用户。

I am consuming an api and I noticed that it comes back with "'s" and not an apostrophe. Since I am not going to be displaying this text in html this will make my text look weird when I display to the user.

如何删除或转换(preferred)?我不知道这个API,我有将派遣更多的这些特殊的codeS的工作,所以我不知道如果我可以简单地通过一次更换。

How can I remove or convert(preferred)? I don't know if this api I am working with will be sending any more of these special codes so I don't know if I can just simply do a replace.

推荐答案

随着.NET 4.0,你可以使用System.Web.HttpUtility.HtmlDe$c$c (驻留在 System.Web.dll中组件,命名空间中的的System.Web )。

As of .NET 4.0 you can use System.Web.HttpUtility.HtmlDecode (resides in the System.Web.dll assembly, in the namespace System.Web).

或您可以使用System.Net.WebUtility.HtmlDe$c$c功能,你甚至不需要为这个额外的参考(因为它驻留在 System.dll中组件,命名空间中的 System.Net )。

Or you could use the System.Net.WebUtility.HtmlDecode function, you don't even need an extra reference for this (because it resides in the System.dll assembly, in the namespace System.Net).

用法:

string myStringToDecode = "Hello 'World'";

string decodedString = System.Web.HttpUtility.HtmlDecode(myStringToDecode);
// or
string decodedString = System.Net.WebUtility.HtmlDecode(myStringToDecode);