Most performant way of converting int to string
Andrew Chapman via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Dec 23 14:29:31 PST 2015
On Wednesday, 23 December 2015 at 11:46:37 UTC, Jakob Ovrum wrote:
> On Wednesday, 23 December 2015 at 11:21:32 UTC, Jakob Ovrum
> wrote:
>> Dynamic memory allocation is expensive. If the string is
>> short-lived, allocate it on the stack:
>
> See also std.conv.toChars[1] for stringifying lazily/on-demand.
>
> http://dlang.org/phobos/std_conv#toChars
Thanks Jakob! I did try toChars but I couldn't quite figure out
a syntax of calling it that the compiler was happy with. From
memory I tried things along the lines of:
string v = toChars!(16,char,LetterCase.lower)(i);
to convert an integer to Hex for example, but the compiler wasn't
happy with it. How would I convert an int to a string using this?
Cheers.
More information about the Digitalmars-d-learn
mailing list