2012-05-24 11 views
14

In che modo D dovrei trasmettere il numero intero alla stringa? Qualcosa comeintero per la conversione di stringhe in D

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

Google mi ha portato la risposta su come farlo con il tango, ma voglio la versione Phobos.

risposta

20
import std.conv; 

int i = 15; 
string message = "Value of 'i' is " ~ to!string(i); 

o format:

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

to è semplicemente geniale :) – Trass3r

7

Usa to da std.conv:

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

ci sono anche wtext un TESTODIN varianti strega torna wstring e dstring.

Problemi correlati