This may seem simple.
It could be vbNewLine
or it can be
However, that is NOT equivalent with "\n"
That is equivalent with
\r\n for non-Unix platforms, or \n for Unix platforms.
What about if I want \n no matter what. \
I tried to search for similar questions and I can't even find it.
There is nothing here either.
So not easy to fine.
Update: One answer says that "\n" means vbNewLine both in windows and in Linux.
Well, I am writing a vb.net windows program that interact with linux machine. You know, usual API stuff. In which case I need a character in windows that always mean "\n" in linux.
Basically, I need the chr(10) character. Not chr(10) chr(13) character.
I think the answer I wrote my self is the answer to that.
And I do not think there is a simple answer on that.
Differences Between vbLf, vbCrLf & vbCr Constants may make things clear. However, people that find that question are people that already guess that vbLf may be a solution.
In fact, the questions and the answers over there do not even link "\n" to vbLF at all. They just say that vbLF is line feed. Is it "\n"? Another technicality
This question answer the question more directly. So what's equivalent to linux/unix "\n" no matter what is vbLf
CodePudding user response:
For VB.Net, which tends to run on Windows, the closest map to \n
is vbCrLf
. This is different than just vbLf
, because vbLf
always maps directly to the ascii line feed character (10
), but \n
on some platforms will map to whatever the local system uses for line endings, rather than a simple line feed. On Windows, this is typically the 13/10 vbCrLf
pair.
The easiest way to include these in code strings is via the new-ish interpolated strings:
$"This string{vbCrLf}includes some{vbCrLf}line breaks."
If you want to go platform-agnostic, the closest match is Environment.NewLine
. And since that's a mouthful to use over and over you can always assing the value to a variable with a shorter name, like this:
Dim vbNl As String = Environment.NewLine
CodePudding user response:
using Microsoft.VisualBasic.CompilerServices;
namespace Microsoft.VisualBasic
{
// Summary:
// Represents a linefeed character for print and display functions.
[__DynamicallyInvokable]
public const string vbLf = "\n";
}
So the answer is
Microsoft.VisualBasic.vbLf
Somehow I can just use vbLf because Microsoft.VisualBasic is so often used it's in my project list I guess.
Update: One answer says that "\n" means vbNewLine both in windows and in Linux.
Well, I am writing a vb.net windows program that interact with linux machine. You know, usual API stuff. In which case I need a character in windows that always mean "\n" in linux.
Basically, I need the chr(10) character. Not chr(10) chr(13) character.
I think vbLf is the right answer.
And I do not think there is a simple answer on that.
Differences Between vbLf, vbCrLf & vbCr Constants may make things clear. However, people that find that question are people that already guess that vbLf may be a solution.
This question answer the question more directly. So what's equivalent to linux/unix "\n", which is the line feed chr(10) character no matter what is vbLf