Windows 记事本不支持换行符 '\n'

发布于 2024-12-25 03:07:37 字数 295 浏览 0 评论 0原文

从我的 iPhone 应用程序中,我将数据从文本输出到文件。当用Windows记事本打开时,数据全部在一行上,并且应该有一个新行的地方出现了一个块字符(表明它是一个无法识别的字符或其他字符)。当用windows写字板打开时,它显示得很好。
我的代码会有问题吗?当我想要换行时,我只是输出 '\n' 。

在此处输入图像描述

注意:它可以与其他编辑器(如 Mac 和 Windows 上的 textedit、MS Word)一起正常工作。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

朦胧时间 2025-01-01 03:07:37

Windows 默认使用 \r\n 作为行尾标记。记事本仅识别这一点,其他文本编辑器可能知道其他行结束样式并正确呈现。

编辑
正如 VonC answers 记事本进行了更新(2018 年),现在可以识别非 Windows 行尾序列。

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.

深居我梦 2025-01-01 03:07:37

当我想要换行时,我只是输出“\n”。

从 2018 年 5 月(6 年后)开始,您将获得换行符!

请参阅“在记事本中引入扩展行结尾支持< /a>”,作者:米歇尔·洛佩兹(以及 他的推文

多年来,Windows 记事本仅支持包含 Windows 行尾 (EOL) 字符 - 回车符 (CR) 和回车符 (CR) 的文本文档。换行(LF)。这意味着记事本无法正确显示在 Unix、Linux 和 macOS 中创建的文本文件的内容。

今天,我们很高兴地宣布我们已经解决了这个问题!

当前的 Windows 10 Insider 版本开始,记事本将照常支持 Unix/Linux 行结尾 (LF)、Macintosh 行结尾 (CR) 和 Windows 行结尾 (CRLF)。

默认情况下,在记事本中创建的新文件将使用 Windows 行结束符 (CRLF),但现在可以查看、编辑和打印现有文件,从而正确维护文件当前的行结束格式。

另请注意,状态栏指示检测到的当前打开文件的 EOL 格式。

看到.bashrc终于正确显示了!

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

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

夜清冷一曲。 2025-01-01 03:07:37

这是因为 \n 在 Windows 中并不代表完整的换行符。使用 \n 是进行换行的“Unix”方式。

在 Windows 上,有像 Notepad++ 这样的文本编辑器可以处理这两种情况,但 Notepad 在这方面确实很愚蠢。

我建议你在 iPhone 应用程序中创建一个设置,用户可以在 Windows 和 Unix 行结尾之间进行选择 - 那么这是他的责任:-)

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

可是我不能没有你 2025-01-01 03:07:37

最近遇到了这个问题,我确信是我的代码正在执行此操作,但事实证明记事本在以正确的格式呈现文件时出现问题。

我们该如何解决这个问题?

记事本的这种行为没有可用的修复方法,但这里有一个可以执行的解决方法列表,以便正确读取内容。

解决方法

  1. 您可以使用 Windows 写字板打开该文件,或者将文件内容粘贴到写字板然后再粘贴回记事本。这应该可以解决问题。

  2. 您还可以使用Notepad++打开第三方文本阅读器的文件,可以安装在Windows系统上。

  3. 微软最近(2018 年 10 月)宣布记事本已在 Windows 10 版本 1809 中得到修复,因此将系统更新到 Windows 10 应该可以解决此问题(1809 之前的 Windows 版本受影响)

微软在 33 年后解决了这个问题!哎呀,解决这个问题花了很长时间不是吗?

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 ?

彡翼 2025-01-01 03:07:37

“微软在 33 年后解决了这个问题!哎呀,解决这个问题花了很长时间,不是吗?”

微软没有修复任何东西。 Unix 使用自己的逻辑(基于文本终端通信逻辑),Apple 使用自己的逻辑(基于假设它们会有所不同),而 Microsoft 产品(这意味着 MS-DOS 和 MS Windows 环境)使用该逻辑这来自于点阵打印机的使用,它是 IBM PC 的第一个输出设备。

要在与 EPSON ESC/P 标准兼容的每台打印机上实现下一行打印,您必须发送 0x0D 0x0A 字符序列,Microsoft World 的逻辑允许您只需发出命令即可在标准打印机上打印标准文本文件: COPY文件名.txt PRN [输入]

"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]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文