【发布时间】:2012-05-24 17:29:07
【问题描述】:
如何在 D 中将整数转换为字符串? 类似的东西
int i = 15
string message = "Value of 'i' is " ~ toString(i); // cast(string) i - also does not work
Google 为我提供了如何使用 tango 的答案,但我想要 phobos 版本。
【问题讨论】:
如何在 D 中将整数转换为字符串? 类似的东西
int i = 15
string message = "Value of 'i' is " ~ toString(i); // cast(string) i - also does not work
Google 为我提供了如何使用 tango 的答案,但我想要 phobos 版本。
【问题讨论】:
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);
【讨论】:
使用来自 std.conv 的to:
int i = 15
string message = "Value of 'i' is " ~ to!string(i);
【讨论】:
import std.conv;
auto i = 15;
auto message = text("Value of 'i' is ", i);
还有 wtext 和 dtext 变体,巫婆返回 wstring 和 dstring。
【讨论】: