2012-05-24 27 views
14

D dilinde tamsayı nasıl alabilirim?Dize dönüştürmede tamsayı, D

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

gibi şey Google bana tango ile yapmak için nasıl cevap getirdi, ama phobos versiyonunu istiyorum. std.conv gelen

cevap

20
import std.conv; 

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

veya format:

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

sadece mükemmel :) – Trass3r

7

Kullanım to:

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); 

ayrıca Dtext cadı wstring ve dstring döndürür varyantları orada wtext edilir.