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?
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}..."
而不是在String中手动包含换行符使用System.Environment.NewLine。
vbCrLf
vbCr
vbLf
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.