no linebreaks where expected

V

Verde

I'm writing text to a file using the following code:

strTemp += "Message: " + tmpMessage.ToString() + "\n" + "Site Number: " +
tempSiteID.ToString() + "\n";
StreamWriter sw = new StreamWriter(logFilePath, true);
sw.Write(strTemp);
sw.Close();

When I open the text file in notepad, there are no linebreaks. instead there
are little black box ASCII characters where the line breaks should be. How
do I get real linebreaks?
 
A

Andreas Håkansson

Verde,

Try using Environment.NewLine instead of \n to do what you
want.

strTemp += "Message: " + tmpMessage.ToString() + Environment.NewLine +
"Site Number: " +
tempSiteID.ToString() + Environment.NewLine;
StreamWriter sw = new StreamWriter(logFilePath, true);
sw.Write(strTemp);
sw.Close();

Hope this helps,

//Andreas
 
S

someone

I'm writing text to a file using the following code:

strTemp += "Message: " + tmpMessage.ToString() + "\n" + "Site Number:
" + tempSiteID.ToString() + "\n";
StreamWriter sw = new StreamWriter(logFilePath, true);
sw.Write(strTemp);
sw.Close();

When I open the text file in notepad, there are no linebreaks. instead
there are little black box ASCII characters where the line breaks
should be. How do I get real linebreaks?

a dos/win line break is actually 2 characters a carriage return(0x0D) and
a line feed (0x0A). the \n is just the new line char so the escape seq
would be \r\n
 
V

Verde

Works great - thanks.


Andreas Håkansson said:
Verde,

Try using Environment.NewLine instead of \n to do what you
want.

strTemp += "Message: " + tmpMessage.ToString() + Environment.NewLine +
"Site Number: " +
tempSiteID.ToString() + Environment.NewLine;
StreamWriter sw = new StreamWriter(logFilePath, true);
sw.Write(strTemp);
sw.Close();

Hope this helps,

//Andreas
 

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