回车符 \r 和换行符 \n 是否应该始终一起使用? \r\n
在 JavaScript 中,这是一个跨浏览器兼容性问题,因此两者都被使用,但在不同语言中有许多实例,我看到两者一起打印为 \r\n。 这是否仍然是普遍例外的规范,即您应该始终使用两者,或者是否有过语言理解两者的时候,而您最终会中断和返回?
In JavaScript this was a cross-browser compatibility issue, so both were used, but there are numerous instances in different languages where I see both printed out together as \r\n. Is this still the generally excepted norm that you should just always use both, or is there ever a time where languages understand both and you end up with a break and a return?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CRLF 对是大多数互联网协议上预期的行尾 (EOL) 标记。
在这里,Postel 的“稳健性原则”应该适用。 对接受的内容要宽松,但对发送的内容要严格。 因此,请做好仅接收 LF 的准备,但如果您要发送数据,请使用相关标准要求的任何内容。
The CRLF pair is the expected end-of-line (EOL) marker on most internet protocols.
Here, Postel's "Robustness Principle" should apply. Be liberal in what you accept, but strict in what you send. So, be prepared to receive just a LF, but if you're sending data use whatever the relevant standards require.
这不是语言兼容性问题,而是文件问题或协议问题。 文件方面:Unix使用\n作为回车符,Windows使用\r\n,我认为MacOS使用(现在不确定)\r。 许多“跨平台”语言将其抽象为平台相关变量。 协议方面:协议指定的内容。
This is not a language compatibility issue, but either a file issue or a protocol issue. File-wise: Unix uses \n as a carriage return, Windows uses \r\n and I think MacOS used (not sure about now) \r. Many 'cross platform' languages abstract this in a platform dependant variable. Protocol-wise: what the protocol specifies.