Preparing text files for different OS’s

If you decide to programmatically write out text to a .txt file for viewing later, it might be handy to know these tips.

Linux/Unix systems will separate each line of text with a single \n escape, signalling the end of a line.

Mac OS reads the end of a line with a single \r carriage return escape.

Microsoft packages such as Notepad reads a sequence of \r\n to declare the end of a line of text.

Obviously, if you’re creating an application destined for the Host OS, you probably know this already. If you wanted to generate reports or logs for use on a different OS, you might find this handy to know, as did I! 👍

Lower level stuff for reference.

ASCII hex for \n (new line)

0x0a

ASCII hex for \r (carriage return)

0x0d

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.