Basic question . . .

  • Thread starter Thread starter Lauchlan M
  • Start date Start date
L

Lauchlan M

How do I add a linefeed (ASCII character 10) to a string?

For example in Delphi I would do

TheString := PreString+ Chr(10) + PostString;

Where Chr(10) whacks in the ascii character for line feed / carriage return
and prestring and poststring are other strings.

How do I do this in C#?

Thanks!

Lauchlan M
 
It depends...

If you simply want to throw a carriage-return linefeed into a string for
display, simply use the \n code. For example:

string strTest = "This is the First Line.\nThis is the Second Line."

If you're writing to a file, you may find the NewLine property of the
TextWriter convenient.

- Carl
 
Also, if you would like to write platform independent code, use
Environment.NewLine instead.
 
Back
Top