[英]showing newline in label
I want to show new line in label using c# but it's not working in every browser. 我想使用c#在标签中显示换行符,但并非在所有浏览器中都有效。
I want to show in xml format in browser. 我想在浏览器中以xml格式显示。
My Code as below 我的代码如下
lblSaleData.Text ="" + "\\n" + "" + eml + "" + ""; lblSaleData.Text =“” +“ \\ n” +“” + eml +“” +“”;
Try This It ll work in most browser.. 尝试此操作将在大多数浏览器中起作用。
lblSaleData.Text = "<Sales>" + "<br/>" +
" <eml>" + eml +
"</eml>" + "<br/>"+ "</Sales>";
<br />
换行符。
Your code produces this result (in the HTML): 您的代码会产生以下结果(以HTML格式):
<Sales>
<eml>eml_value</eml></Sales>
The browser should interpret any whitespaces (including line breaks, as a single space), so it would probably display like (in the browser) 浏览器应将任何空格(包括换行符,解释为单个空格)解释为,因此可能显示为(在浏览器中)
<Sales> <eml>eml_value</eml></Sales>
using a HTML tag that is designed for line breaks ( 使用专门用于换行符的HTML标签(
) forces the browser to insert a break where you want it, so )强制浏览器在所需位置插入一个中断,因此
lblSaleData.Text ="<Sales>" + "<br / >" + "<eml>" + eml + "</eml>" + "</Sales>";
will yield 将产生
<Sales>
<eml>eml_value</eml></Sales>
in the browser 在浏览器中
If you want an HTML line break, use <br />
as suggested. 如果要HTML换行,请按照建议使用
<br />
。
If what you want is to show nicely laid-out HTML source in a label, use System.Environment.Newline
. 如果要在标签中显示布局良好的HTML源,请使用
System.Environment.Newline
。 I normally stick it as a static readonly string NL
at the top of a file. 我通常将其作为静态只读字符串
NL
粘贴在文件顶部。
Looks like you're printing out XML on the screen, right? 看起来您正在屏幕上打印XML,对不对? The Label control is automatically HTML-Encoding your text, so that the angle brackets aren't treated as html elements.
Label控件会自动对文本进行HTML编码,因此尖括号不会被视为html元素。
The newline character doesn't show on the screen, because <br />
is the correct html element for a newline. 屏幕上不会显示换行符,因为
<br />
是换行符的正确html元素。
我会用:
lblSaleData.Text =String.Format("<Sales><br /><eml>{0}</eml></Sales>",eml);
“ Line1” +“ <br />” +“ Line 2”将解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.