如何在标签中显示带有空格的文本

问题描述:


我正在从数据库中获取文本以使其工作正常,但是它没有在文本之间显示大量空白...?如何显示与数据库中相同的文本...


i am fetching text from database into label its working fine, but it is not showing the lots of white space between the text...?how it is possible to show text same as it is in databse...

将数据发送到Web浏览器时,它将空格字符串压缩为单个空格-不管数据源如何.为了解决这个问题,请将您的空格转换为& nbsp;"总是显示为单个空格字符,并且不会被压缩为单个空格.
在设置label.Text值之前,可以在字符串上使用string.Replace(",& nbsp;").
[edit] Arrgggh!浏览器吞下了&"号分号,并用空格替换了! -OriginalGriff [/edit]
When you send data to a web browser, it squashes strings of spaces to a single space - regardless of the data source. To get round this, convert your spaces to " " which are always shown as a single space character and do not get squashed into a single spaces.
You could use string.Replace(" ", " ") on your string before you set the label.Text value.

[edit]Arrgggh! Browser swallowed the ampersand nbsp semicolon and replaced it with space! - OriginalGriff[/edit]


要在HTML页面中显示空格,可以使用 实体.

只需用 实体替换空格.

有关HTML实体的更多信息,您可以查看以下链接: http://www.w3schools.com/html/html_entities.asp [ ^ ].

For more information about HTML entities, you can see that link: http://www.w3schools.com/html/html_entities.asp[^].


您好尝试此代码


< asp:label style =字母间距:3像素;" id ="Label1" runat ="server"/>
Hello try this code


<asp:label style="letter-spacing: 3px;" id="Label1" runat="server" />