Windows notepad not supporting newline character '\n'

白昼怎懂夜的黑 提交于 2019-11-26 11:30:23

问题


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

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


回答1:


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.




回答2:


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!




回答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 :-)



来源:https://stackoverflow.com/questions/8755029/windows-notepad-not-supporting-newline-character-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!