On 01/13/2016 01:20 PM, H. S. Teoh via Digitalmars-d-learn wrote:

std.format.formattedWrite will do
writeln-formatting into a buffer (well, any output range, really) -- I'm
pretty sure it doesn't allocate, at least for the simplest cases like
converting an integer. So you should be able to do something like this:

        auto data = [ 1, 2, 3, 4, 5 ];
        char[] buf = ...;
        formattedWrite(buf, "[%(%d, %)]", data);

And buf can be an Appender:

import std.stdio;
import std.format;
import std.array;

void main() {
    auto data = [ 1, 2, 3, 4, 5 ];

    auto buf = appender!string(); // Or appender!(char[]) if needed
    formattedWrite(buf, "[%(%d, %)]", data);

    assert(buf.data == "[1, 2, 3, 4, 5]");
}

Ali

Reply via email to