之间的区别和  [英] Difference between   and  

查看:112
本文介绍了 之间的区别和 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以解释 和& nbsp; ?



我有以二进制形式存储在数据库中的html数据,其中的空格可以是& nbsp;   或有时 



另外问题是,当我使用 JSoup lib 将此HTML转换为纯文本时正确地转换它,但如果我使用java的String.contains(我的字符串)方法。它看起来像& nbsp; 的HTML数据不同于  。字符串不能在反之亦然。



例子:

HTML1:这 是  my  test  string



HTML2:这& nbsp;是& nbsp; my& amp; amp; nbsp; ; nbsp; test& nbsp; string



如果我使用JSoup将它转换为纯文本。它返回

HTML 1:这是我的测试字符串



HTML 2:这是我的测试字符串

p>

但是两个字符串仍然不相同。为什么会这样?

解决方案

  是经典空间,当你打开你的空格键时获得的空间,由他的HTML实体等价物表示。

& nbsp;   代表非破坏性空间,通常用于防止浏览器崩溃多个空间聚会:

 & amp ;    =>(折叠成只有一个空格)

& nbsp;& nbsp;& nbsp;& nbsp; =>     (未折叠)



如果您正在解析包含经典和非空白空格的字符串,则可以安全地替换另一个。


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?

解决方案

  is the classic space, the one you get when you hit your spacebar, represented by his HTML entity equivalent.

  and   represents the non-breaking space, often used to prevent collapse of multiple spaces togethers by the browser :

"    " => " " (collapsed into only one space)

"    " => "    " (not collapsed)

If you are parsing a string containing both classic and non-breaking spaces, you can safely replace one by the other.

这篇关于 之间的区别和 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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