Difference between   and  

Viewed 26922

Can any one explain me difference between   and   ?

I have html data stored in database in binary form and space in that can be either of   or   or sometimes  .

Also issue is when I convert this HTML to plain text using JSoup lib it is converting it properly but if I use String.contains(my string) method of java. It looks like the HTML data which is having   is different from which is having  . String is not found in either vice versa.

Example:

HTML1 : This is my test string

HTML2 : This is my test string

If I convert it to plain text using JSoup. It returns

HTML 1 : This is my test string

HTML 2 : This is my test string

But still both string are not same. Why is it so?

5 Answers

To complete the other answers...

Apart from the non-breaking line and the collapsing of multiple spaces, the HTML rendering will not be exactly the same in fact even if most answers say the contrary and that is true in general.

Let's take an example :

<span>&#32;test</span> <br/>
<span>&#160;test</span>

The first span will not contain a space in the beginning of the string, while the second span will. It's surely part of the collapsing behavior : https://en.wikipedia.org/wiki/Non-breaking_space.

So in this case, if you need this first space, the difference is important.

Related