pelleg
pelleg

Reputation: 19

how to add Linebreak to a string in asp.net vb

I tried everything, but nothing seems to work!

How the do I put a breakline?!

Dim textMsg as String
textMsg = Body.text & Environment.Newline & _ q1.text & Environment.Newline & _ q2.text & Environment.Newline & _ q3.text & Environment.Newline & _ q4.text '

please help

(with corrent code I get an error cuz of the & Environment.Newline & _ ")

Upvotes: 1

Views: 15208

Answers (5)

Jonathan
Jonathan

Reputation: 12025

I preffer .Net Style:

& Environment.NewLine &

It's Is exactly the same that

& (vbCrLf) &

Upvotes: 0

Stokke
Stokke

Reputation: 2011

Try this:

dim textMsg as String
textMsg = Body.text & vbNewLine

Upvotes: 0

pelleg
pelleg

Reputation: 19

thats the right one:

& (vbCrLf) &

Upvotes: 0

Peter
Peter

Reputation: 27944

You should add a br:

textMsg = Body.text & "<BR/>" & _ q1.text & "<BR/>" & _ q2.text & "<BR/>" & _ q3.text & "<BR/>" & _ q4.text

Or you can try: Str & VBNewLine OR Str & VBCrLf

Or set the email message to html. The the
will work.

Upvotes: 2

Joel Coehoorn
Joel Coehoorn

Reputation: 415665

Since you tagged this asp.net, I'll guess that this newline should appear in a web page. In that case, you need to remember that you are creating html rather than plain text, and html ignores all whitespace... including newlines. If you view the source for your page, you'll likely see that the new lines do make it to your html output, but they are ignored, and that's what is supposed to happen. If you want to show a new line in html, use a <br> element:

textMsg = Body.text & "<br>" & _ q1.text & "<br>" & _ q2.text & "<br>" & _ q3.text & "<br>" & _ q4.text 

The code above will place the text on several lines. It's interesting that if you view the source now, you'll see that everything is all on the same line, even though it uses several lines for display.

Upvotes: 3

Related Questions