回车顺序和换行符 [英] Order of carriage return and new line feed

查看:99
本文介绍了回车顺序和换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有正确的回车顺序然后换行很重要吗?对于文本编辑器,它们以什么顺序显示是否重要?

Is it important to have the correct order of carriage return then new line feed? For text editors does it matter in what order they appear?

例如代替

\r\n

这个

\n\r

似乎杰夫(Jeff)已经准备好一个非常不错的 博客文章 .

Seems like Jeff has allready writen up a very nice Blog Post on the subject.

推荐答案

同时使用两个控制字符的传统顺序是回车,然后是换行.

The traditional order, when both control characters are used, is Carriage Return, then Line Feed.

这样做的原因可以追溯到旧的ASR-33电传打字机.

The reason for this goes back to the old ASR-33 Teletype.

当向ASR-33发出运输退货时,如果打印头在右边距附近,则需要十分之一秒的时间才能返回到左边距,此外还有一点弹跳"当左边距被击中时.

When a Carriage Return is issued to an ASR-33, the print head, if it is near the right margin, takes over a tenth of a second to return to the left margin, plus there is a bit of "bounce" when the left margin is hit.

如果顺序是换行,然后是回车,则第一个打印的字符可能会在回车后十分之一秒出现,因此可能会在页面的一半处打印(作为拖尾).但是,如果换行是在回车之后进行的,那么换行所花费的时间将为打印头提供额外的时间来完成其行程.

If the order were Line Feed, then Carriage Return, the first printed character might occur a tenth of a second after the Carriage Return, and thus might end up printing (as a smear) halfway across the page. But if Line Feed comes after Carriage Return then the time taken by the Line Feed provides extra time for the print head to complete it's trip.

某些系统(例如,我在考虑使用旧的Xerox Sigma 7操作系统)先进行换行,然后再进行回车,但它们会将NULL字符注入数据流,以使打印头完成任务.

Some systems (I'm thinking the old Xerox Sigma 7 OS, eg) do Line Feed then Carriage Return, but they inject, eg, NULL characters into the data stream to allow the print head to do it's thing.

当然,当您使用速度更快的设备(例如,一些早期的30 CPS电传打印机)时,问题变得更加严重,并且需要更复杂的策略.

And, of course, when you get to faster devices (some early 30 CPS teleprinters, eg), the problem gets worse and a more complex strategy is required.

(还有一点,对于用户输入,回车是由用户按回车键提供的,而换行必须由计算机提供.因此,这通常是样式"正常打印行开始带有换行, end 带有回车符,提示用户输入仅包含换行,而用户输入以回车.此方案在一致使用时效果很好,但当然并非总是如此.

(There is also the point that, for user input, the Carriage Return is provided by the user pressing the Return key, while the Line Feed must be provided by the computer. For this reason it was often the "style" to have normal print lines begin with Line Feed and end with Carriage Return. A prompt for user input, then, consisted only of a Line Feed, while the user input ended with the Carriage Return. This scheme worked well when used consistently, but of course that didn't always happen.)

这篇关于回车顺序和换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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