误用 导致长英文字符串不换行
从网上下载过一个UBB的转换成HTML的函数(c#),内中就有这么一句:
str = str.Replace(" "," ");
<DIV style="PADDING-RIGHT: 10px; PADDING-LEFT: 10px; FONT-SIZE: 14px; FLOAT: right; PADDING-BOTTOM: 0px; MARGIN: 5px 0px 15px; VERTICAL-ALIGN: top; WIDTH: 475px; PADDING-TOP: 0px; TEXT-ALIGN: left
">Enter a search and the closest matches will start to appear as you type by quote, author and tag.QuoteView, rate and collect quotes. Learn the history and context of a famous quote or add your own knowledge about a quote.Author Find quotes by person. Learn or share a little bit about an author via their mini bio.TagsSearch using keywords (called Tags) that members have tagged quotes and authors with. Search all tags or just the tags you have submitted.CommunitySign up for our free membership and start tagging, submitting, rating and collecting quotes as a member of our community.</DIV>
str = str.Replace(" "," ");看起来没什么问题," "在HTML中就是空格的意思啊,没什么可疑的地方。这样的代码在处理中文的时候也没什么问题,唯独在处理英文的时候,出现了网上广为流传的“长英文字符串不换行”问题,我查阅了网上流传的各种版本的文章,解决办法也是五花八门,各有不同,WOAD-BREAK,CSS,Javascript等等,我也曾经按图索骥,在国外的英文网站中查找上述方法的痕迹,奇怪的是,竟然一无所获。这一点让我大惑不解,郁闷了很长时间。
就在今天,就在刚才,当我第N次研究这个问题的时候,百无聊赖的我第一次察看起我的网站生成的HTML代码:
<DIV style="PADDING-RIGHT: 10px; PADDING-LEFT: 10px; FONT-SIZE: 14px; FLOAT: right; PADDING-BOTTOM: 0px; MARGIN: 5px 0px 15px; VERTICAL-ALIGN: top; WIDTH: 475px; PADDING-TOP: 0px; TEXT-ALIGN: left
">Enter a search and the closest matches will start to appear as you type by quote, author and tag.QuoteView, rate and collect quotes. Learn the history and context of a famous quote or add your own knowledge about a quote.Author Find quotes by person. Learn or share a little bit about an author via their mini bio.TagsSearch using keywords (called Tags) that members have tagged quotes and authors with. Search all tags or just the tags you have submitted.CommunitySign up for our free membership and start tagging, submitting, rating and collecting quotes as a member of our community.</DIV>大量的 强烈的刺激了我的神经,难道是 搞得鬼?回想起研究过的几个英文网站,似乎并没有这么多 啊?于是我尝试将所有的 换成空格,保存,重新打开页面,IE窗口底部长长的滚动条消失了,问题奇迹般的解决了!!!
至此,尽管问题解决了,但是我并没有搞清楚为什么会出现这样的问题,没办法,只好祭出google大杀器。
感谢神圣和伟大的google,他无私的为我搜索到的下面资料,汇总一下,给同样出现“长英文字符串不换行”问题的朋友参考,或许您的问题并没有其他文章所说的那么复杂。
的全名是none-break space,意思是非断行空白、或者连续空白。
跟普通的空格相比,是两个不同的字符,其unicode码各不相同,标准HTML忽略连续2个以上空格,只显示一个,此外 作为html所定义的一个实体,不能在xml中使用。
道理是浅显的,错误是隐蔽的,教训是惨痛的。
浙公网安备 33010602011771号