01-21-2010, 02:22 AM
Function join
function'str ARRAY(str)&tokens [str'delimiter]
// the reverse of tok()
// concatenate an array of strings separated by delimiter
//
// example 1; tokenize then re-join
// str s1 = "IBM,MSFT,GE"
// ARRAY(str) A
// tok(s1 A ",") ;; tokenize list into array A
// str s2 = join(A "+") ;; re-join with new delimiter, s2 is "IBM+MSFT+GE"
//
// example 2; make a comma delimited, quote qualified list
// ARRAY(str) A2; A2.redim(4)
// A2[0] = "now is"
// A2[1] = "the time"
// A2[2] = "for all good"
// A2[3] = "men"
// str s3 = join(A2, "'',''")
// s3.from("''" s3 "''") ;; "now is","the time","for all good","men"
int i; int n = tokens.len
str result
if (n == 0) ;; default for empty array
,ret result
// start with the first token,
// then concatenate delimiter and subsequent tokens
result = tokens[0]
for i 1 n
,result.from(result, delimiter, tokens[i])
,
ret result
,