HTML编码空间的HtmlDecode不是空间 [英] HtmlDecode of html encoded space is not space

查看:100
本文介绍了HTML编码空间的HtmlDecode不是空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



直到现在,我还认为HttpUtility.HtmlDecode(& nbsp;")是一个空格.但是下面的代码总是返回false.

Hi,

Till now I was thinking HttpUtility.HtmlDecode(" ") was a space. But the below code always returns false.

string text = " ";

text = HttpUtility.HtmlDecode(text);

string space = " ";

if (String.Compare(space, text) == 0)
  return true;
else
  return false;




与Server.HtmlDecode()尝试时相同

为什么会这样?




Same when I try with Server.HtmlDecode()

Why is it so?

Any help would be much appreciated

推荐答案

您使用htmlEncode对字符串进行编码
您使用htmlDecode解码字符串,

进行编码/解码以除去空格和特殊字符或转义字符.

You use htmlEncode to encode the string
You use htmlDecode to decode the string,

The encoding/decoding is done to remove whitespaces and special or escaped characters.

(" ") is simply non-breaking space 




试试看,看看你得到什么




try this and see what you get

string text = " ";
string space = "";

text = HttpUtility.HtmlEncode(text);
space = HttpUtility.HtmlDecode(text);

if (String.Compare(space, text) == 0)
  return true;
else
  return false;


这篇关于HTML编码空间的HtmlDecode不是空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆