[Issue 13480] Input range formatting should not format as "elements"

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Sep 16 01:02:31 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13480

--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Jakob Ovrum from comment #0)
> writefln statement #2 and #3 don't make any sense. Formatting characters and
> strings using the element markup style (`formatElement`), which forces
> single and double quotes around the character or string respectively,
> defeats the purpose of range-based formatting, which allows you to customize
> the fluff around each element.

If you want to stop automatic element quoting, you can use "%-(".

void main()
{
    auto ror = ["one", "two", "three"];
    writefln("%-(%s%| %)", [1, 2, 3]); // 1 2 3
    writefln("%-(%s%| %)", "abc");     // a b c
    writefln("%-(%s%|, %)", ror);      // one, two, three
}

It's documented in: http://dlang.org/phobos/std_format

> Inside a compound format specifier, strings and characters are escaped
> automatically. To avoid this behavior, add '-' flag to "%(".

--


More information about the Digitalmars-d-bugs mailing list