Search code examples
castingdphobos

integer to string conversion in D


How in D would I cast integer to string? Something like

int i = 15
string message = "Value of 'i' is " ~ toString(i); // cast(string) i - also does not work 

Google brought me the answer on how to do it with tango, but I want the phobos version.


Solution

  • import std.conv;
    
    int i = 15;
    string message = "Value of 'i' is " ~ to!string(i);
    

    or format:

    import std.string;
    string message = format("Value of 'i' is %s.", i);