Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Join array of strings in d

Tags:

string

d

In python I can do this:

In [1]: x = ["a", "b", "c"]

In [2]: "--".join(x)
Out[2]: 'a--b--c'

Is there an equivalent trick in d?

like image 555
qed Avatar asked Jul 16 '26 16:07

qed


1 Answers

Yes, use std.array.join:

import std.array, std.stdio;

void main()
{
    auto x = ["a", "b", "c"];
    writeln(x.join("--"));
}

Note that D's argument order is reversed when compared to Python's.

like image 158
Vladimir Panteleev Avatar answered Jul 19 '26 08:07

Vladimir Panteleev