On Monday, 25 January 2021 at 18:45:11 UTC, Rempas wrote:
Actually what the title says. For example I have dchar c = '\u03B3'; and I want to make it into string. I don't want to use "to!string(c);". Any help?

char[] dcharToChars(char[] buffer, dchar value)
{
    import std.range : put;
    auto backup = buffer;
    put(buffer, value);
    return backup[0 .. $ - buffer.length];
}

void main()
{
    dchar c = '\u03B3';
    char[4] buffer;
    char[] protoString = dcharToChars(buffer, c);

    import std.stdio;
    writeln("'", protoString, "'");
}

Unfortunately, `put` is not @nogc in this case.

Reply via email to