Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

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

C#
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
Posted
Updated 26-Nov-12 1:41am
v3
Comments
Richard MacCutchan 26-Nov-12 8:00am    
What is the value of text after the call to HtmlDecode()?

1 solution

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

C#
string text = " ";
string space = "";

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

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900