How to covert dchar and wchar to string?
Steven Schveighoffer
schveiguy at gmail.com
Tue Jan 26 15:25:47 UTC 2021
On 1/25/21 1:45 PM, 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?
That's EXACTLY what you want to use, if what you want is a string.
If you just want a conversion to a char array, use encode [1]:
import std.utf;
char[4] buf;
size_t nbytes = encode(buf, c);
// now buf[0 .. nbytes] contains the char data representing c
-Steve
[1] https://dlang.org/phobos/std_utf.html#encode
More information about the Digitalmars-d-learn
mailing list