digitalmars.D - String-Interpolation
- Matthias Becker (13/13) Dec 19 2004 Some languages, mainly scripting-languages, have a feature called string
- teqDruid (6/25) Dec 19 2004 SomeType instance = new SomeType();
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (20/24) Dec 19 2004 Or you could do it yourself at runtime, if needed:
- FEATURE (23/48) Dec 19 2004 I agree with Matthias Becker.
- Paul Bonser (4/23) Jan 14 2005 How about using `s (backward single-quotes, on the ~ key)? It's a lot
- Brad Anderson (5/7) Dec 19 2004 Yes, it was a very good article. And did you notice on the cover, D is
- teqDruid (2/11) Dec 19 2004 I hadn't noticed that, and I just went to check it. Awesome!
-
Carlos Santander B.
(11/11)
Dec 19 2004
"Brad Anderson"
escribió en el mensaje - Paul Bonser (4/15) Jan 14 2005 Dang, my copy hasn't come yet...or my subscription ran out...Hopefully
Some languages, mainly scripting-languages, have a feature called string interpolation: So you can use variables in string literals. This is a cool feature. Perhaps it would be nice to have it in D: This gets translated to: "." -- Matthias Bekcer
Dec 19 2004
SomeType instance = new SomeType(); char[] str = format("the text representation of instance is %s.", instance); I like the writef family. BTW... I just got my latest DDJ with Walter's "Printf Revisited"... good article Walter! John On Sun, 19 Dec 2004 13:57:51 +0000, Matthias Becker wrote:Some languages, mainly scripting-languages, have a feature called string interpolation: So you can use variables in string literals. This is a cool feature. Perhaps it would be nice to have it in D: This gets translated to: "." -- Matthias Bekcer
Dec 19 2004
teqDruid wrote:"."SomeType instance = new SomeType(); char[] str = format("the text representation of instance is %s.", instance);Or you could do it yourself at runtime, if needed: import std.stdio; import std.string; char[] interpolate(char[] string, char[][char[]] vars) { foreach(char[] key; vars.keys) string = replace(string, "$" ~ key, vars[key]); return string; } void main() { char[][char[]] vars; vars["foo"] = "bla"; writefln( interpolate("the value of foo is $foo.", vars) ); } --anders PS. I'm sure D newcomers just *love* char[][char[]] ? Wouldn't string[string] be easier on the eyes... (ye olde "alias char[] string;" debate all over)
Dec 19 2004
I agree with Matthias Becker. My sugestion is to use '"Special string"' Stats with '" ends with "' So empty string would be '""' So we don't haveto change the behavior of "" strings. First cool feature would be, that you can use " in there. For example write('"Then he said:"I have enaugh" and leaved."'); instead on write("Then he said:\"I have enaugh\" and leaved."); With \" the code seems to get ugly and not very readable. And there you could use $ also I suggest: -------------------- int a; a=5; write('"a equals $a; And I say to you:"Have a good day!" "'); -------------------------- Where ; ends the variable. without it is not very clear, where the variable should end. The $ starts the variable. The $$ could represent the dollar. I think it is very important to make the code easyer to read! write("a equals "~toString(a)~" And I say to you:\"Have a good day!\" "); What do you think? In article <pan.2004.12.19.14.17.44.434407 teqdruid.com>, teqDruid says...SomeType instance = new SomeType(); char[] str = format("the text representation of instance is %s.", instance); I like the writef family. BTW... I just got my latest DDJ with Walter's "Printf Revisited"... good article Walter! John On Sun, 19 Dec 2004 13:57:51 +0000, Matthias Becker wrote:Some languages, mainly scripting-languages, have a feature called string interpolation: So you can use variables in string literals. This is a cool feature. Perhaps it would be nice to have it in D: This gets translated to: "." -- Matthias Bekcer
Dec 19 2004
FEATURE wrote:I agree with Matthias Becker. My sugestion is to use '"Special string"' Stats with '" ends with "' So empty string would be '""' So we don't haveto change the behavior of "" strings. First cool feature would be, that you can use " in there. For example write('"Then he said:"I have enaugh" and leaved."'); instead on write("Then he said:\"I have enaugh\" and leaved."); With \" the code seems to get ugly and not very readable. And there you could use $ also I suggest: -------------------- int a; a=5; write('"a equals $a; And I say to you:"Have a good day!" "'); --------------------------How about using `s (backward single-quotes, on the ~ key)? It's a lot cleaner (and prettier) than using doubled quotes at each end. -PIB
Jan 14 2005
teqDruid wrote:I like the writef family. BTW... I just got my latest DDJ with Walter's "Printf Revisited"... good article Walter!Yes, it was a very good article. And did you notice on the cover, D is now one of the listed languages at the top? I'm not sure how long they've been doing that, but it was pretty cool to see. BA
Dec 19 2004
On Sun, 19 Dec 2004 19:07:14 -0600, Brad Anderson wrote:teqDruid wrote:I hadn't noticed that, and I just went to check it. Awesome!I like the writef family. BTW... I just got my latest DDJ with Walter's "Printf Revisited"... good article Walter!Yes, it was a very good article. And did you notice on the cover, D is now one of the listed languages at the top? I'm not sure how long they've been doing that, but it was pretty cool to see. BA
Dec 19 2004
"Brad Anderson" <brad dsource.dot.org> escribió en el mensaje news:cq58l9$1tku$1 digitaldaemon.com... | Yes, it was a very good article. And did you notice on the cover, D is | now one of the listed languages at the top? I'm not sure how long | they've been doing that, but it was pretty cool to see. | | BA I'm not sure about that. It seems to change every month according to the content of the issue. ----------------------- Carlos Santander Bernal
Dec 19 2004
Brad Anderson wrote:teqDruid wrote:Dang, my copy hasn't come yet...or my subscription ran out...Hopefully just hasn't come :( -PIBI like the writef family. BTW... I just got my latest DDJ with Walter's "Printf Revisited"... good article Walter!Yes, it was a very good article. And did you notice on the cover, D is now one of the listed languages at the top? I'm not sure how long they've been doing that, but it was pretty cool to see. BA
Jan 14 2005