On 03/17/2010 12:59 PM, Gabriel Laskar wrote:
Hi,

I am searching how to do a formatted string like with sprintf()

I have found std.format.formattedWrite() but when I try :

Appender!(string) msg;
formattedWrite(msg, "toto: %0", 42);
writeln(msg);

It fails with :
core.exception.rangeer...@�(1582): Range violation

I have also found std.string.format, but it seems to fail also.

Oops, I'm stupid, It is not %0, but %s... std.string.format is good.
Now I need to pass an array of char[] instead of va_args, I have found
a work around, but it seems bad :

string formatArray(char[][] args)
{
  switch (args.length)
  {
    case 1: return format(args[0]);
    case 2: return format(args[0], args[1]);
    // ...
  }
}

If someone have something better...

Cheers.

__
Gabriel Laskar <[email protected]>

Reply via email to