Like {0}, {1}, etc. Became the standard for formatting strings?

Just wondering about this in development history ... how do parentheses with an array index ( {0} , {1} , etc.) become the standard string formatting?

Any special meaning, or something that someone chose from the 80s in the air? A.

+4
source share
3 answers

In fact, back in the 80s, the format string standard was printf , with format strings such as %d for integers or %s for strings, and obscure format modifiers (e.g. %06d , which draws an integer and pad it left with zeros until it reaches six characters). The reason was that the type C system was very bad and it was impossible for printf to guess what data was received (was it a pointer to a string? A floating-point integer), which made it necessary to indicate the type of arguments inside the format string. This approach has remained.

This format was ported from C (and C ++) to many languages ​​(Java, PHP, OCaml, Scilab ...) and several tools (e.g. Firebug console.log ).

The earliest I saw the format {0} was in C # in the early 2000s. I haven't seen it outside of C # so far.

+5
source

Taligent MessageFormat . 1990 year. Also in JDK 1.1 (which came from Taligent) and ICU (==)

+2
source

I'm not sure if this is the actual origin, but the ICU (International Components for Unicode) project uses curly braces in a message format format and was released as an open source in 1999. As far as I know, this is not a standard, but it's nice to have some kind of agreement on Unicode text formatting processing between different programming languages ​​(at least implementations / bindings exist for C ++, Java and PHP (not sure about C #)) . You can learn more about the entire project at userguide.icu-project.org.

0
source

All Articles