Windows compatibility with Unix/Linux newline “\n”

text processingtext-encodingwindows

A follow-up to Difference between '\n' and '\r\n'.

It's been few decades since the schism was introduced. Nowadays, when documents are being exchanged over the internet, typically with no prior knowledge of the client's preference of line endings, the clients have to deal with both \n, \r\n.

To me it seems that it's safe to use \n only. Software produced by Microsoft can process both. The major plain text editors can too. Browsers, IDEs, file managers, office suites, all these can do it.

Is there any point in writing software to use CRLF or is it practically ok to just unify at "\n"? Are there known problems with "\n" in any major modern Windows software?

EDIT: The issue is not with the software itself. Indeed the software can use some kind of NL constant which resolves at runtime. However, the generated files are about to be transferred, and hardly converted on each occasion.

Imagine a company where the originating machine of a content/document can be any platform, and the consuming too. And the way of transferring the documents can be any (mail, shared drive, download,…) In such scenario, there is no way to prevent content using \n appearing on Windows, and vice versa. Hence the question.

Best Answer

As far as Windows and C# is involved you can always use the Environment.Newline

to determine the default new line character of the system the program is ran on.

also, you can use text.Replace("\n","\r\n") to switch to windows return.

There are still compatibility issues when managing files and especially office related ones, some arcane COM apis are also newline sensitive.

Related Topic