Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New line in VB.NET

Tags:

vb.net

Why, when I do im my code:

"Land Location \\r\\n Roundoff (C)"

I see the \\r\\n and not a new line feeder at the output?

Any idea how to do that?

As I said I must have only one string there, without using a "&". Can I put that vbCrLf inside of my string somehow?

like image 847
Night Walker Avatar asked Mar 16 '26 12:03

Night Walker


2 Answers

There is no \ escape codes in VB so you can't put a line break in a string literal. The only escape character in VB strings is the double quotation marks used to insert a quotation mark in a string.

You can use the VB constant for a Windows type line break:

"Land Location " & vbCrLf & " Roundoff (C)"

For the code to be platform independent, you should use the NewLine property instead:

"Land Location " & Environment.NewLine & " Roundoff (C)"

Whether you should use the platform independent code or not depends on the situation.

If you need it as a single string for some reason, you would have to use a marker for the line break, that you replace when you use the string:

Dim s As String = "Land Location \n Roundoff (C)"
s = Replace(s, "\n", Environment.NewLine)
like image 80
Guffa Avatar answered Mar 19 '26 01:03

Guffa


May be "Land Location " & vbCR & vbLF .....

--

Edit: per @JeffSahol's comments, you can use string interpolation since VB 14, so it can be like

$"...{vbCrLf}..."

like image 28
YOU Avatar answered Mar 19 '26 00:03

YOU



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!