Click to See Complete Forum and Search --> : Normalize line endings, how?


ireland
June 1st, 2007, 04:26 AM
I'm working with Visual studio, I'm writing to a file, when I open the file in Visual Studio's text editor I get the following error:

"The line endings in the following file are not consistent. Do you want to normalize the line endings?"

How can I normalize the line endings from code before displaying the file?

Visual Studios error prompts you to normalize, I've compared a normalized and un-normalized file, the only difference I see is the File Type is different in the files properties, the normalized files type is "PC" the un-normalized in "Unknown", is this a clue?

S_M_A
June 1st, 2007, 04:33 AM
It seems like when you write your file you sometimes use PC end-of-line CR/LF and sometimes unix end-of-line that is only a LF.

Edit: Should have mentioned. The proper way to add a newline character is by using Environment.NewLine. I.e. String myStr = "Some text" + Environment.NewLine;

ireland
June 1st, 2007, 04:53 AM
SMA,
You are bang on, I just came across it in the msdn docs and then tried it before you're response and it'sexactly what the problem was.
Environment.NewLine instead of \n is the solution. :)
Lovely jubely.

S_M_A
June 1st, 2007, 05:00 AM
Nice to hear! :)

Mona777
January 13th, 2009, 09:03 AM
Hi Guys,

I have the same problem but not sure what you mean by Environment.NewLine???? Where do I do this and how?

Many thanks

TheCPUWizard
January 13th, 2009, 09:05 AM
Edit: Should have mentioned. The proper way to add a newline character is by using Environment.NewLine. I.e. String myStr = "Some text" + Environment.NewLine;Of course if you are using a "WriteLine" method, then this is done implicitly, and you do NOT add a newline (in any form) to the data itself....

ireland
January 13th, 2009, 09:17 AM
Hi Guys,

I have the same problem but not sure what you mean by Environment.NewLine???? Where do I do this and how?

Many thanks
http://msdn.microsoft.com/en-us/library/system.environment.newline.aspx