Converting int to dchar?
Seb via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jul 31 14:46:37 PDT 2016
On Sunday, 31 July 2016 at 21:31:52 UTC, Darren wrote:
> Hey, all.
>
> I'm pretty much a programming novice, so I hope you can bear
> with me. Does anyone know how I can change an int into a char
> equivalent?
>
> e.g.
> int i = 5;
> dchar value;
> ?????
> assert(value == '5');
>
> If I try and cast it to dchar, I get messed up output, and I'm
> not sure how to use toChars (if that can accomplish this).
>
> I can copy+paste the little exercise I'm working on if that
> helps?
>
> Thanks in advance!
Ehm how do you you want to represent 1_000 in one dchar?
You need to format it, like here.
import std.format : format;
assert("%d".format(1_000) == "1000");
Note that you get an array of dchars (=string), not a single one.
More information about the Digitalmars-d-learn
mailing list