split()
in的对立面是awk
什么?想象一下,我有数组包含字符/整数。
我试过的:
color = "#FFFF00";
printf("color original: %s\n", color);
split(color, chars, "");
joined = "";
for (i=1; i <= length(chars); i++) {
joined = joined + chars[i];
}
printf("color joined: %s\n", joined);
但是输出是:
color original: #FFFF00
color joined: 0
这当然是不正确的。
更新: 很酷,最终得到以下代码(灵感来自答案中的连接函数):
color = "#FFFF00";
printf("color original: %s\n", color);
split(color, chars, "");
joined = "";
for (i=1; i <= length(chars); i++) {
joined = joined "" chars[i];
}
printf("color joined: %s\n", joined);
诀窍是在加入事物时不要使用+
符号