Lines are represented differently in different operating systems. For most non Unix Platforms the new line is represented as: “\r\n” And for Unix Platforms the new line is represented as: “\n” I’ve found that most developers will hard code these values into their code, for example:
string someText = String.Format(“This is a line1.{0} This is line 2.”, @”\n”);
That works, but there is a built in property in the .NET Framework to retrieve the current platforms New Line. This property is Environment.NewLine. Here’s an example, using the same code above, but with Environment.NewLine in place of the hardcoded value.
string someText = String.Format(“This is a line1.{0} This is line 2.”, Environment.NewLine);
This property will return the new line string defined for the environment that the application is running in.
Leave a Reply
You must be logged in to post a comment.