veda
veda

Reputation: 6594

asp.net : I wanted to know how to insert '\n' on the label

I am just simply creating a web application. I wanted to insert a line break in a label

for example

label1.Text = "I AM HERE" + "\n" + "I AM NOW HERE";

I wanted to print it as

I AM HERE

I AM NOW HERE

But, it is not working... I don't know why...

I even tried

label1.Text = "I AM HERE" + '\n' + "I AM NOW HERE";

its not working.. What should I do....

Upvotes: 2

Views: 6483

Answers (3)

zs2020
zs2020

Reputation: 54524

Use <br /> instead of \n.

Upvotes: 9

ZX12R
ZX12R

Reputation: 4826

To insert line breaks use the
tags.

To insert spaces use the  .

Label1.Text="First line<br/>Second line with &nbsp;&nbsp; more spaces"

Upvotes: 3

Kyle Rosendo
Kyle Rosendo

Reputation: 25277

Use the <br /> tag. This will create a breaking space (or newline) in the label, e.g.:

label1.Text = "I AM HERE<br />I AM NOW HERE";

As a side note. You do not need to seperate out \n's in your coding. In future where you can use it, you can simply go:

"I AM HERE\nI AM NOW HERE";

And this will add in the new line for you.

Upvotes: 2

Related Questions