By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,052 Members | 1,303 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,052 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Oct 3 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Fred Dag" <fr*****@hostvilleit.comwrote in message
news:e6**************@TK2MSFTNGP04.phx.gbl...
[...]
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
Oct 3 '06 #2

P: n/a
Peter Duniho wrote:
"Fred Dag" <fr*****@hostvilleit.comwrote in message
news:e6**************@TK2MSFTNGP04.phx.gbl...
>[...]
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
Oct 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.