17

From my iPhone application I'm outputting data from text to a file. When opened with windows notepad, the data is all on one line and where there should be a new line a block character is present (showing that it's an unrecognized character or something). When opened with windows wordpad, it displays just fine.
Would there be something wrong in my code? I'm simply output '\n' when i want a new line.

enter image description here

NOTE : It's working fine with other editors like textedit, MS Word on mac as well as on windows.

2

5 Answers 5

23

Windows default is to use \r\n as end-of-line marker. Notepad only recognises that, other text editors may know about other line-end styles and render correctly.

EDIT
As VonC answers Notepad had an update (in 2018) where it now can recognize non-Windows end-of-line sequences.

2
  • So I'm doing an echo -e "blah-blah\r\n more text" in a bash script,and it still doesn't come up as two lines in notepad. What am I doing wrong?
    – Ray
    Aug 19, 2015 at 21:29
  • @Ray It does come up as two lines at least in Win7 Notepad
    – golimar
    Nov 22, 2019 at 11:47
8

I'm simply output '\n' when i want a new line.

And starting May 2018 (6 years later), you will get a newline!

See "Introducing extended line endings support in Notepad" by Michel Lopez (and his tweet)

For many years, Windows Notepad only supported text documents containing Windows End of Line (EOL) characters - Carriage Return (CR) & Line Feed (LF). This means that Notepad was unable to correctly display the contents of text files created in Unix, Linux and macOS.

Today, we’re excited to announce that we have fixed this issue!

Starting with the current Windows 10 Insider build, Notepad will support Unix/Linux line endings (LF), Macintosh line endings (CR), and Windows Line endings (CRLF) as usual.

New files created within Notepad will use Windows line ending (CRLF) by default, but it will now be possible to view, edit, and print existing files, correctly maintaining the file’s current line ending format.

Also note that the status bar indicates the detected EOL format of the currently open file.

See an .bashrc finally displayed correctly!

https://msdnshared.blob.core.windows.net/media/2018/05/Notepad-after.png

3

This is because \n does not represent a full line break in Windows. Using \n is "the Unix" way of doing line breaks.

On Windows, there are text-editors like Notepad++ which handle both, but Notepad is really dumb in that respect.

I suggest you create a setting in your iPhone application where the user can choose between Windows and Unix line endings - then it's his responsibility :-)

1

Recently ran into this issue and I was convinced that it was my code which is doing this but turns out Notepad has problems rendering the file in the right format.

How do we fix this?

There is no fix available of this behavior of notepad but here is a list of workarounds that can be performed in order to read the contents correctly.

Workaround

  1. You can use Windows WordPad to open the file or just paste the contents of the file into WordPad and back into Notepad . This should fix the problem .

  2. You can also use Notepad++ to open the files which is a third-party text reader and can be installed on a windows system.

  3. Microsoft recently (October 2018) announced that Notepad has been fixed in Windows 10 version 1809 so updating your system to windows 10 should resolve this issue (Windows versions before 1809 are impacted)

Microsoft fixed this after 33 years !!! Gee thats a long time to fix the issue aint it ?

0

"Microsoft fixed this after 33 years !!! Gee thats a long time to fix the issue aint it ?"

Microsoft did not fix anything. Unix was using its own logic (based on text terminals communication logic), Apple was using its own logic (based on the assumption that they will be different) and Microsoft products (this means MS-DOS and MS Windows environments) was using the logic that came from the usage of the dot matrix printers that were first output devices for IBM PCs.

To achieve printing in the next line on every printer that was EPSON ESC/P standard-compatible You have to send the 0x0D 0x0A character sequence, and Microsoft World's logic allows you to print standard text files on standard printers simply by issuing a command: COPY filename.txt PRN [Enter]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.