CrLf with C#

  • Thread starter Thread starter Rafael Veronezi
  • Start date Start date
R

Rafael Veronezi

How can I concatenate e CrLf in C#?
Like in VB.Net we have the VbCrLf constant...
I Know that there's the "\n" that calls a new line, but I don't know if it
works, since the string I am building with the CrLf will be written to a
file...
 
I will have to check, but I believe it is "\n\r". The easiest way to test is
open the file in Notepad. With CrLf, you will see a new line. With either Cr
or Lf, you will see a box where the character appears.

Another option is to set up ASCII 10 and ASCII 13, concatenated, as a string
constant and use that constant in your code. To do this, set up a char for
each and cast and concetenate into a string.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Rafael Veronezi said:
How can I concatenate e CrLf in C#?
Like in VB.Net we have the VbCrLf constant...
I Know that there's the "\n" that calls a new line, but I don't know if it
works, since the string I am building with the CrLf will be written to a
file...

CRLF itself is always "\r\n". That may or may not be the same as
Environment.NewLine, depending on the platform.

I'm not sure why you think that it being written to a file affects
things though...
 
Correction: I think it is "\r\n". WIth Windows, Environment.NewLine also
works. Thanks

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
It could be,
but it doesn't work with the file I wrote using that..
Testing Environment.NewLine now..
 
Rafael Veronezi said:
It could be,
but it doesn't work with the file I wrote using that..

Could you say *exactly* in what way it doesn't work?
Testing Environment.NewLine now..

That won't change anything, assuming you're using the MS .NET CLR.
You'll get exactly the same effect as just "\r\n"
 
"\n\r" doesn't work... It outputs a strange character when you open the file
with an text editor...
With the Environment.NewLine it's ok...
 
You have it backwards...it's "\r\n", with \r being "return" and \n being
"newline". Environment.Newline is better to use, though, since it is
platform-independent (in theory...I'd have to run it on Mono to be sure)


Rafael Veronezi said:
"\n\r" doesn't work... It outputs a strange character when you open the file
with an text editor...
With the Environment.NewLine it's ok...
 
Back
Top