Most performant way of converting int to string

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at
Wed Dec 23 15:07:26 PST 2015

On 12/23/2015 02:29 PM, Andrew Chapman wrote:

 > 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?

I had to squint at the error message to understand that the 16 
specialization for radix requires that the value is unsigned. The 
following works:

import std.conv;
import std.algorithm;

void main() {
     assert(1234u    // <-- unsigned
            .toChars!(16, char, LetterCase.lower)


More information about the Digitalmars-d-learn mailing list