StreamWriter.WriteLine() vs .Write("\n") and missing newlines when writing to files with the later

F

Fred Dag

Hi,
When writing using both these methods ( StreamWriter.Write("\n") vs
WriteLine() ) to a file and open in Notepad I see a special character
instead of newlines with Write("\n") vs a newline with WriteLine().

How do I insert characters into a string ( ie "line 1\nline 2\n" ) so that
when I write them to Stream they will be interpreted properly as newlines?

Thanks in advance
 
P

Peter Duniho

Fred Dag said:
[...]
How do I insert characters into a string ( ie "line 1\nline 2\n" ) so that
when I write them to Stream they will be interpreted properly as newlines?

Notepad doesn't understand a single newline character by itself. You need a
carriage return as well ("\r\n").

Alternatively, you can open your file in WordPad, which does treat the
single newline character as a line break.

Pete
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Peter said:
Fred Dag said:
[...]
How do I insert characters into a string ( ie "line 1\nline 2\n" ) so that
when I write them to Stream they will be interpreted properly as newlines?

Notepad doesn't understand a single newline character by itself. You need a
carriage return as well ("\r\n").

"line 1\r\nline 2" or if one is a portability pedantic
"line 1" + Environment.NewLine + "line 2".

Arne
 

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