C# Encoding a text string with line breaks

jim picture jim · Jul 27, 2009 · Viewed 211.4k times · Source

in C# I have a string I am writing to the outputstream of the response. After I save this document and open it in Notepad++ or WordPad I get nicely formatted line breaks where they are intended, when I open this document with the regular old windows notepad, I get one long text string with [] square looking symbols where the line breaks should be.

Has anyone had any experience with this?

Thanks

Jim

Answer

Jon Skeet picture Jon Skeet · Jul 27, 2009

Yes - it means you're using \n as the line break instead of \r\n. Notepad only understands the latter.

(Note that Environment.NewLine suggested by others is fine if you want the platform default - but if you're serving from Mono and definitely want \r\n, you should specify it explicitly.)