arrays - 如何将整数数组转换为字符串?

标签 arrays string int type-conversion d

我需要转换数组 int s 到字符串。按照代码执行此操作,但结果我收到了不需要的符号 [ ]

import std.stdio;
import std.conv;

void main()
{
    int [] x = [1,3,4,6];
    string s = to!string(x);
    writeln(s);
}

输出:[1, 3, 4, 6]如何使用 replace 在不破解的情况下删除括号?

最佳答案

例如,您可以这样做:

import std.stdio;
import std.conv;
import std.algorithm;

void main()
{
    int [] x = [1,3,4,6];
    writeln(x.map!(to!string).joiner(", "));
}

关于arrays - 如何将整数数组转换为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36581856/

相关文章:

c++ - 打印以在c++中在线的特定位置输出

javascript - JS : deserializing a string with a JSON-like structure

python - 为什么我会收到 TypeError : can't multiply sequence by non-int of type 'float'

javascript - 无法以 Angular 过滤日期

java - Android:循环遍历字符串数组 - Intent 方法的逻辑需要帮助

java - 二维java数组

arrays - 使用 Int 对数组进行排序

c - 使用递归反转字符串

c++ - 在 C++ 中将 int 14236 转换为 hex 379C 作为 char[37,9C]

c - 将 Int 添加到字符串