Custom separator in array format

Malte no at valid.mail
Tue Jan 28 07:36:25 UTC 2020


I want to format an array using the %(...%) syntax. How can I 
change the separator? I tried to use ? and add it as additional 
parameter, but that doesn't seem to work on arrays:

import std;
void main()
{
     writeln("This works:");
     writefln("%,2?d", '_', 2000); // 20_00

     auto vec = [1000, 2000, 3000];
     writeln("This should fail (separator character expected) but 
the ? is just ignored:");
     writefln("%(%,2?d\t%)", vec); // 10,00	20,00	30,00
     writeln("This throws:");
     writefln("%(%,2?d\t%)", '_', vec); // 
std.format.FormatException@/dlang/dmd/linux/bin64/../../src/phobos/std/format.d(2271): incompatible format character for integral argument: %(
}


More information about the Digitalmars-d-learn mailing list