Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HtmlDecode of html encoded space is not space

Tags:

c#

asp.net

vb.net

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;

Same when I try with Server.HtmlDecode()

Why is it so?

Any help would be much appreciated

Thanks, N

like image 451
user1481853 Avatar asked Nov 26 '12 12:11

user1481853


1 Answers

The HTML entity   doesn't represent a space, it represents a non-breaking space.

The non-breaking space has character code 160:

string nbspace = "\u00A0";

Also, as Marc Gravell noticed, you have double encoded the code, so you would need to decode it twice to get the character:

string text = " ";
text = HttpUtility.HtmlDecode(HttpUtility.HtmlDecode(text));
like image 57
Guffa Avatar answered Oct 12 '22 13:10

Guffa