use*_*853 12 c# vb.net asp.net
直到现在我才想到的HttpUtility.HtmlDecode(" ")是一个空间.但是下面的代码总是返回false.
string text = " ";
text = HttpUtility.HtmlDecode(text);
string space = " ";
if (String.Compare(space, text) == 0)
return true;
else
return false;
Run Code Online (Sandbox Code Playgroud)
当我尝试时也一样 Server.HtmlDecode()
为什么会这样?
任何帮助将非常感激
谢谢,N
Guf*_*ffa 15
HTML实体 不代表空格,它代表一个不间断的空间.
不间断空格的字符代码为160:
string nbspace = "\u00A0";
Run Code Online (Sandbox Code Playgroud)
此外,正如Marc Gravell注意到的那样,您对代码进行了双重编码,因此您需要对其进行两次解码才能获得该字符:
string text = " ";
text = HttpUtility.HtmlDecode(HttpUtility.HtmlDecode(text));
Run Code Online (Sandbox Code Playgroud)