到目前为止,我在想HttpUtility.
HtmlDecode(“& nbsp;”)是一个空格.但是下面的代码总是返回false.
string text = " "; text = HttpUtility.HtmlDecode(text); string space = " "; if (String.Compare(space,text) == 0) return true; else return false;
当我尝试使用Server.HtmlDecode()时,
为什么会这样?
任何帮助将不胜感激
谢谢,
ñ
解决方法
@H_403_16@ HTML实体& nbsp;不代表空间,它代表一个不间断的空间.不间断空格的字符代码为160:
string nbspace = "\u00A0";
另外,正如Marc Gravell所注意到的那样,你已经对代码进行了双重编码,所以你需要对它进行两次解码以获取字符:
string text = " "; text = HttpUtility.HtmlDecode(HttpUtility.HtmlDecode(text));