I need convert array of int
s to string. Following code doing it, but in result I am getting unwanted symbols [
]
import std.stdio;
import std.conv;
void main()
{
int [] x = [1,3,4,6];
string s = to!string(x);
writeln(s);
}
output: [1, 3, 4, 6]
How I can remove brackets without hack with replace
?
You can do it for example like this:
import std.stdio;
import std.conv;
import std.algorithm;
void main()
{
int [] x = [1,3,4,6];
writeln(x.map!(to!string).joiner(", "));
}
You can use std.format
import std.format;
import std.stdio;
void main()
{
auto res = format("%(%s, %)", [1,2,3,4,5]);
writeln(res); // output: 1, 2, 3, 4, 5
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With