如何在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版本.
我尝试编译以下代码:
import std.algorithm;
void main()
{
string[] x = ["ab", "cd", "ef"]; // 'string' is same as 'immutable(char)[]'
string space = " ";
char z = joiner( x, space ).front(); // error
}
Run Code Online (Sandbox Code Playgroud)
dmd带有错误的结尾编译:
test.d(8): Error: cannot implicitly convert expression (joiner(x,space).front()) of type dchar to char
Run Code Online (Sandbox Code Playgroud)
更改char z为dchar z确定错误消息,但我很感兴趣,为什么它出现在第一位.
为什么结果joiner(string[],string).front()是dchar而不是char?
(文档http://dlang.org/phobos/std_algorithm.html#joiner中没有任何内容)
有人会说什么std.algorithm.map回报?(链接到一些文档页面将非常感激)从错误消息其结果是类型Result
ulong[] x = [1,2,3];
ulong[] y = std.algorithm.map!"a"(x); // Error: cannot implicitly convert <..> of type Result to ulong[]
Run Code Online (Sandbox Code Playgroud)
在http://dlang.org/phobos/std_algorithm.html#map中,关于它的信息非常少:
The call map!(fun)(range) returns a range of which elements are obtained by applying fun(x) left to right for all x in range
Run Code Online (Sandbox Code Playgroud)
由此我不清楚,我能做什么或不能做什么.
D编程语言中的空字符串是什么?
字符串是字符数组(http://dlang.org/arrays.html#strings)
可能:alias immutable(char)[] string
基于那个空字符串应该是一个空数组.但那么,空数组是什么样的东西?
有任何想法吗?