CrLf with C#

  • Thread starter Rafael Veronezi
  • 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...
 
C

Cowboy \(Gregory A. Beamer\)

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!
**********************************************************************
 
J

Jon Skeet [C# MVP]

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...
 
C

Cowboy \(Gregory A. Beamer\)

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!
**********************************************************************
 
R

Rafael Veronezi

It could be,
but it doesn't work with the file I wrote using that..
Testing Environment.NewLine now..
 
J

Jon Skeet [C# MVP]

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"
 
R

Rafael Veronezi

"\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...
 
K

Keith Patrick

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top