在Red和Rebol(3)中,您可以使用split
函数将字符串拆分为项目列表:
>> items: split {1, 2, 3, 4} {,}
== ["1" " 2" " 3" " 4"]
join
字符串中项目列表的相应反函数是什么?它的工作方式类似于以下内容:
>> join items {, }
== "1, 2, 3, 4"
答案 0 :(得分:1)
有rejoin做旧的修改
"language":
{
"processing": "<span style='width:100%;'><img src='http://www.snacklocal.com/images/ajaxload.gif'></span>",
"url": "http://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/German.json"
}
将其称为 rejoin / with [..] delimiter
但我很确定,还有其他更老的解决方案。
答案 1 :(得分:1)
还没有内置功能,你必须自己实现它:
>> join: function [series delimiter][length: either char? delimiter [1][length? delimiter] out: collect/into [foreach value series [keep rejoin [value delimiter]]] copy {} remove/part skip tail out negate length length out]
== func [series delimiter /local length out value][length: either char? delimiter [1] [length? delimiter] out: collect/into [foreach value series [keep rejoin [value delimiter]]] copy "" remove/part skip tail out negate length length out]
>> join [1 2 3] #","
== "1,2,3"
>> join [1 2 3] {, }
== "1, 2, 3"
根据请求,这里的功能分为更多行:
join: function [
series
delimiter
][
length: either char? delimiter [1][length? delimiter]
out: collect/into [
foreach value series [keep rejoin [value delimiter]]
] copy {}
remove/part skip tail out negate length length
out
]
答案 2 :(得分:0)
以下功能有效:
myjoin: function[blk[block!] delim [string!]][
outstr: ""
repeat i ((length? blk) - 1)[
append outstr blk/1
append outstr delim
blk: next blk ]
append outstr blk ]
probe myjoin ["A" "B" "C" "D" "E"] ", "
输出:
"A, B, C, D, E"