如何在D中将整数转换为字符串?就像是
int i = 15
string message = "Value of 'i' is " ~ toString(i); // cast(string) i - also does not work
Run Code Online (Sandbox Code Playgroud)
谷歌给我带来了关于如何使用探戈的答案,但我想要的是phobos版本.
Ber*_*ard 22
import std.conv;
int i = 15;
string message = "Value of 'i' is " ~ to!string(i);
Run Code Online (Sandbox Code Playgroud)
或者format:
import std.string;
string message = format("Value of 'i' is %s.", i);
Run Code Online (Sandbox Code Playgroud)
to从std.conv 使用:
int i = 15
string message = "Value of 'i' is " ~ to!string(i);
Run Code Online (Sandbox Code Playgroud)