Multiple %s format specifiers with a single argument
Jonathan M Davis
jmdavisProg at gmx.com
Mon Apr 9 10:27:42 PDT 2012
On Monday, April 09, 2012 19:08:54 Andrej Mitrovic wrote:
> import std.string;
>
> void main()
> {
> string foo = "foo";
> string bar = format("%s %s %s", foo);
> }
>
> format expects 3 arguments, but what I really want is foo to be used
> for all 3 specifiers and not repeat 'foo' 3 times manually. Are there
> any format specifiers that do what I want? I've tried using positional
> specifiers but that didn't work:
>
> string bar = format("%1$s %1$s %1$s", foo);
> $ std.format.FormatException at std\format.d(4363): string
>
> That's a great error message btw.
Posix positional arguments seem to work for writefln but not format for
whatever reason. Report it as a bug.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list