2012-05-24 45 views
14

如何在D中將整數轉換爲字符串? 喜歡的東西D中的字符串轉換整數

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

谷歌給我帶來了關於如何與探戈做的答案,但我要的火衛一的版本。

回答

20
import std.conv; 

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

format

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

只是精彩:) – Trass3r

7

使用to從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); 

也有wtext的DTEXT變種女巫返回的wstring和dstring。