换行符表示为"\ r".在Mac上? [英] Line break represented as "\r" on Mac?

查看:79
本文介绍了换行符表示为"\ r".在Mac上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参见小提琴:如果您在最近的文本区域中按 Enter 在Mac上, newline 字符似乎由 \ r 表示,这与这个这个问题维基百科.总结这些链接:

See fiddle: if you press Enter in the textarea on a recent Mac, the newline character appears to be represented by \r, which would be in direct contrast to the answers to this, this and this question and to Wikipedia. To summarise these links:

  • \ r 代表旧Mac(OS 9及更高版本)上的换行符
  • \ n 表示UNIX系统(OS X,Linux)上的换行符
  • \ r \ n 表示Windows上的换行符.
  • \r represents a line break on old Macs (OS 9 and before)
  • \n represents a line break on UNIX systems (OS X, Linux)
  • \r\n represents a line break on Windows.

当我在JSFiddle中按Enter时,得到以下结果(OS X 10.11.6):

When I press Enter in the JSFiddle, I get the following result (OS X 10.11.6):

textarea: \r

span: \n

此行为花了很长时间才弄清楚,似乎不合逻辑.潜在的基本原理是什么?

This behaviour took a long time to figure out and seems illogical. What could be the underlying rationale?

推荐答案

我相信您会混淆两件事:

I believe you're confusing two things:

  1. 按Enter键会产生什么字符代码?
  2. 在哪些平台上使用什么行尾?

据我所知,对于所有平台,#1的答案都是13(ASCII回车符"\ r").

As far as I know, the answer to #1 is 13 (ASCII carriage return, "\r") for all platforms.

您是否有一个平台,您所看到的不是 ?

Do you have a platform where this is not what you're seeing?

这篇关于换行符表示为"\ r".在Mac上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆