加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – HtmlDecode的html编码空间不是空格

发布时间:2020-12-15 04:15:31 所属栏目:百科 来源:网络整理
导读:到目前为止,我在想HttpUtility. HtmlDecode(“ nbsp;”)是一个空格.但是下面的代码总是返回false. string text = "nbsp;";text = HttpUtility.HtmlDecode(text);string space = " ";if (String.Compare(space,text) == 0) return true;else return false; 当
到目前为止,我在想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()时,

为什么会这样?

任何帮助将不胜感激

谢谢,
?

解决方法

HTML实体& nbsp;不代表空间,它代表一个不间断的空间.

不间断空格的字符代码为160:

string nbspace = "u00A0";

另外,正如Marc Gravell所注意到的那样,你已经对代码进行了双重编码,所以你需要对它进行两次解码以获取字符:

string text = " ";
text = HttpUtility.HtmlDecode(HttpUtility.HtmlDecode(text));

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读