字符串转义码(\n、\t...)源自何处?

发布于 2024-08-10 05:19:07 字数 94 浏览 3 评论 0原文

纯粹想知道...因为它们今天仍然存在并在 C# 中使用...

使用字符串转义码的模式从何而来?它首先以什么语言出现?哪些语言(如果有)以不同的方式解决了问题?

Purely wondering... since they're still around and in use in C# today...

Where did the pattern of using string escape codes come from? What language did it first appear in? What languages, if any, have solved the problem in a different way?

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

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

发布评论

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

评论(1

聽兲甴掵 2024-08-17 05:19:07

我怀疑这些转义码源自 B,一种用于 Honeywell 6000 GCOS 操作系统的高级汇编编程语言。这种语言是贝尔实验室基于英国语言 BCPL 开发的。由于 BCPL 相当冗长,B 开发人员简化了语法并添加了大括号等内容来替换 BEGIN 和 END。这就是 B 名称的由来,因为它是 BCPL 的缩写形式。

后来贝尔实验室的一些人创建了一种语言,它是 B 的后继者,主要是添加了类型和标准 I/O 库。因为是B的继任者,所以他们选择了BCPL这个名字中的下一个字母。

我不记得在 B 之前看到过反斜杠符号,并且由于 C 和 UNIX 从 B 继承了它,所以我认为 B 是这个符号的起源,或者更具体地说,贝尔实验室是起源。这种表示法完全有可能在 B 之前的其他贝尔实验室软件中使用,因为他们是一个多产的软件生产商,其中大部分免费分发给大学,例如我在 1970 年代中期就读的大学。

顺便说一句,转义序列的想法早在这之前就已经存在,可以追溯到 19 世纪的博多码,它是一种固定长度的 5 位二进制代码,旨在取代可变长度的莫尔斯电码。 Baudot 具有 SI(Shift In)和 SO(Shift Out)代码,可以将字母转义为大写变体,就像打字机上的 Shift 键一样。

I suspect that these escape codes originated in B, a high-level assembly programming language for the Honeywell 6000 GCOS operating system. This language was developed at Bell Labs based on a British language called BCPL. Because BCPL was rather wordy, the B developers simplified the syntax and added things like braces to replace BEGIN and END. That's where the name B came from, because it was an abbreviated form of BCPL.

Later on some people at Bell Labs created a language that was the successor to B, mainly by adding typing and a standard I/O library. Because it was B's successor, they chose the next letter in the name BCPL.

I do not recall seeing the backslash notation before B, and since C and UNIX inherited it from B, I thing that B is the origin of this notation, or more specifically, that Bell Labs was the origin. It's entirely possible that this notation was used in other Bell Labs software before B, since they were a prolific producer of software, much of which was distributed freely to universities such as the one which I attended in the mid 1970's.

By the way, the idea of an escape sequence existed long before that, dating back to the 19th century Baudot code which was a fixed length 5 bit binary code intended to replace variable length Morse code. Baudot had SI (Shift In) and SO (Shift Out) codes that escaped letters into their capital variation, just like the Shift key on a typewriter.

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