D语言新手问题 如何将字符串分割成数组?

· Created · Last modified by yunfeng~ replied at · 1509 times read

PHP使用explode分割
JAVA使用split分割

D语言使用的是split分割
使用split是需要引用std.array库

string str = "Learning,D,is,fun";
writeln(str.split(","));
writeln(split(str, ","));
//输出结果:["Learning", "D", "is", "fun"]

更详细的内容请参考https://dlang.org/library/std/array/split.html

数组转字符串代码:

string[] strArr = ["Learning", "D", "is", "fun"];
string str = strArr.join(",");
writeln(str);
// 输出结果:"Learning,D,is,fun"

Login to reply