Multiple %s format specifiers with a single argument

q66 quaker66 at gmail.com
Mon Apr 9 10:11:32 PDT 2012


On Monday, 9 April 2012 at 17:09:03 UTC, 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.

Positional specifier works just fine for me.


More information about the Digitalmars-d-learn mailing list