Replace \ n with \ r \ n - the way Windows controls represent newlines (but see the note below):
textBox1.Text = generatedCode.Replace("\n", "\r\n");
or
textBox1.Text = generatedCode.Replace("\n", Environment.NewLine);
Note. As discussed in the comments, you can use Environment.NewLine . However, it is unclear - it is not determined which element of the Windows Forms line separator should use if it does not work on Windows. Should they use the default platform or a single Windows (like the Windows GUI management port)? One example on MSDN uses Environment.NewLine , but so far I have seen terribly incorrect examples on MSDN, and the documentation just doesn't say what should be.
In an ideal world, we will have only one line separator - and even in the second best world, each situation will clearly determine which line separator he expected ...
Jon Skeet Nov 17 '09 at 20:02 2009-11-17 20:02
source share