誤用 導致長英文字符串不換行
從網上下載過一個UBB的轉換成HTML的函數(c#),內中就有這麼一句:
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>
">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中使用。
跟普通的空格相比,是兩個不同的字符,其unicode碼各不相同,標準HTML忽略連續2個以上空格,只顯示一個,此外 作爲html所定義的一個實體,不能在xml中使用。
道理是淺顯的,錯誤是隱蔽的,教訓是慘痛的。