拆分awk的对面 [英] awk opposite of split
问题描述
什么是拆分()
在 AWK
相反?
想象一下,我有数组containig字符/整数。
what would be an opposite of split()
in awk
?
Imagine I have array containig characters/integers.
我已经试过:
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
这当然是不正确的。
更新:
很酷,结束了以下code(通过加入解答功能present启发):
UPDATE: cool, ended up with the following code (inspired by join function present in answers):
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);
加入的东西回来时,诀窍是不要使用 +
标志
推荐答案
知道了)相反的拆分(
是加入()
,仅仅是谷歌搜索给了我这个页面,这似乎包含的解决方案:的 http://www.gnu.org/software/gawk/manual/html_node/Join-Function.html 。它加入一个数组中的所有元素一起,并返回对应的字符串。
Knowing that the opposite of split()
is join()
, a mere Google Search gives me this page, which seems to contain the solution : http://www.gnu.org/software/gawk/manual/html_node/Join-Function.html . It joins all the elements of an array together, and returns the corresponding string.
['f','o','o'] => "foo"
有乐趣
这篇关于拆分awk的对面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!