{0}、{1} 等如何成为格式化字符串的标准?
只是对发展历史中的这一点感到好奇......带有数组索引的括号({0}
、{1}
等)是如何成为标准的字符串格式化?
有什么特殊意义,或者是 80 年代有人从空中捡到的东西吗?
Just curious about this in the history of development... how did brackets with the array index ({0}
, {1}
, and so on) become the standard of string formatting?
Any special significance, or something somebody picked out of midair in the 80's?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实际上,早在 80 年代,格式化字符串标准是
printf
,格式字符串例如用于整数的%d
或用于字符串的%s
,以及晦涩的格式修饰符(例如%06d
,它绘制一个整数并用零将其向左填充,直到达到六个字符)。原因是 C 类型系统很差,printf
不可能猜测它接收到的数据是什么(是指向字符串的指针?整数?浮点数) )这使得有必要指定格式字符串内参数的类型。这种方法仍然存在。这种格式从 C(和 C++)继承到许多语言(Java、PHP、OCaml、Scilab...)和多种工具(例如 Firebug 的
console.log
函数)。我最早看到
{0}
格式是在 2000 年代初的 C# 中。到目前为止,我在 C# 之外还没有见过很多这样的东西。Actually, back in the 80's, the formatting string standard was
printf
, with format strings such as%d
for integers or%s
for strings, and obscure format modifiers (such as%06d
which draws an integer and pads it to the left with zeros until it reaches six characters). The reasoning was that the C type system was very poor, and it was impossible forprintf
to guess what the data it received was (was it a pointer to a string? an integer? a floating-point number) which made it necessary to specify the type of the arguments inside the format string. This approach remained.This format was carried over from C (and C++) to many languages (Java, PHP, OCaml, Scilab...) and several tools (Firebug's
console.log
function, for instance).The earliest I've seen the
{0}
format was in C#, in the early 2000s. I haven't seen it a lot outside C# so far.Taligent MessageFormat。 20 世纪 90 年代。也在 JDK 1.1(来自 Taligent)和 ICU (==)
Taligent MessageFormat. 1990s. Also in JDK 1.1 (which came from Taligent) and ICU (==)
我不确定它是否是真正的起源,但 ICU(Unicode 国际组件)项目在 消息格式化,于 1999 年首次作为开源发布。据我所知,它不是一个标准,但很高兴在不同编程语言之间处理 Unicode 文本格式方面达成某种形式的协议(位于C++、Java 和 PHP 存在最少的实现/绑定(不确定 C#))。您可以在 userguide.icu-project.org 上阅读有关整个项目的更多信息。
I'm not sure whether it is the actual origin, but the ICU (International Components for Unicode) project uses curly braces in message formatting and was first released as open source in 1999. To my knowledge it is not a standard, but it is nice to have some form agreement on the handling of Unicode text formatting between different programming languages (at least implementations/bindings exist for C++, Java and PHP (not sure about C#)). You can read more about the entire project at userguide.icu-project.org.