openlang

turning an integer into text with D

What is D's way of converting an integer into a string? For example

int amount = 27
string caption = "Number in 'amount': " ~ toString(amount); // cast(string) amount fails too

Searching Google found instructions using tango, whereas I'm looking for the phobos equivalent.

The conversation continues 3

Follow the reasoning
  1. Permalink

    Try std.conv's to function:

    int amount = 27
    string caption = "Number in 'amount': " ~ to!string(amount);
  2. Permalink
    import std.conv;
    
    int amount = 27;
    string caption = "Number in 'amount': " ~ to!string(amount);

    alternatively, format:

    import std.string;
    string caption = format("Number in 'amount': %s.", amount);
  3. Permalink
    import std.conv;
    auto amount = 27;
    auto caption = text("Number in 'amount': ", amount);

    wtext and dtext are anothr variants which produce wstring and dstring reslts.

Other sides of the same question

  1. Escaping percent characters when calling String.Format?

    My strings.xml file holds a SQL query, and I'm trying to construct the finished string in code with String.Format. The SELECT…

    Replies 3Latest activity java
  2. NAK only when the message has a degree sign (serial, Emacs)

    Basically, Temp: 23C gets an ACK but Temp: 23°C gets a NAK, and the board shows nothing. The log line is rx: "\25". Lowering…

    Replies 1Latest activity emacs-lisp
  3. Formatting strings with F#

    I'm building an F# library for the first time Using string.Format gives me a complaint saying that the function doesn't exist…

    Replies 2Latest activity fsharp