开发者

New line in VB.NET

开发者 https://www.devze.com 2022-12-13 05:57 出处:网络
Why, when I do im my code: \"Land Location \\\\r\\\\n Roundoff (C)\" I see the\\\\r\\\\nand not a new line feeder at the output?

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 o开发者_运维知识库nly one string there, without using a "&". Can I put that vbCrLf inside of my string somehow?


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)


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}..."


Instead of including the newline manually in the String use System.Environment.NewLine.


vbCrLf
vbCr
vbLf
0

精彩评论

暂无评论...
验证码 换一张
取 消