"\n" in streamwriter

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi,

Im writing an app where I need to write a large string to a textfile. The
string comes from a template file (loaded from resource), and already
contains formatting such as new lines and tabs.

I have some tokens in the string that I do a "replace" with. The replacement
text is generated myself (ie in code) and contains tabbing and new line
characters ("\t" & "\n").

Thing is, when I reopen the file in notepad, both the existing and new
formatting is all OK except that it is not starting new lines. My
replacement text is all on the same lines.

Here is some psuedo code:

string strTemplate = ... //Load from resource file
using (StreamWriter Output = new StreamWriter(@"\My Documents\Test.cs",
false))
{
string strReplacementText = "\t\t\tThis is sample text\n\t\t\tThis is
some more\n";
string NewString = strTemplate.Replace("SomeToken", strReplacementText);
Output.Write(NewString);
}

The tabs come through ok, but no line feeds :(

tia
j
 

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

Back
Top