no linebreaks where expected

  • Thread starter Thread starter Verde
  • Start date Start date
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?
 
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
 
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
 
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
 
Back
Top