What is the universal newline for all operating systems? (LF and CR)

Viewed 7998

When I write a file using Delphi it's on a Windows machine and the text files it puts out work fine on windows. When I use it on a Mac though it's expecting the formatting to be a bit different. On Mac the newline is different and it can't always read the Windows files.

How can I make my files readable by mac programs?

6 Answers

Very old thread that is still very relevant. The easiest way to handle this and other situations when you get text data from different operating is to start by normalise the information first. This is Javascript but you should be able to change it into any other language easy enough.

        body = body.replace(/(\r\n|\r)/g,"\n");

In most languages it could be translated into this (but in JS it will just replace the first occurance.)

        body = body.replace("\r\n","\n");
        body = body.replace("\r","\n");

It will simply make sure that newline is represented by "\n" , if you want for instance windows format you simply add after the above..

        body = body.replace("\n","\r\n");
Related