std.string.format

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Dec 26 07:13:00 PST 2006


Egor Starostin wrote:
> I have a couple of issues with std.string.format.
> 
> 1. why
> writefln(format("%%1.%df",2));
> produces 'Error: std.format'

Because the format function returns "%1.2f", so writefln expects an 
extra floating-point argument after that string.
What you may be after is
	writefln("%s", format("%%1.%df",2));

> but
> writefln(format(format("%%1.%df",2),1.0));
> works fine?

Here the outer format call returns "1.00" which is a regular string, so 
writefln() doesn't have a problem with it.


If you're passing a string to writefln() that contains % signs you want 
to be sent to the console, either make sure they're properly quoted 
(i.e. %% instead of %) or pass a format string that expects a string 
before it (e.g. "%s").
If you don't want them to be sent to the console but want them to be 
interpreted and substituted, make sure you supply the correct number 
(and type) of arguments...



More information about the Digitalmars-d mailing list