join
Joins a list of strings into a single string.
Syntax
-
join(L[, f][, sep[, li[, ri[, lo[, ro]]]]])
-
L
is a list of strings -
f
is a string-transforming function -
sep
is a string -
li
is a string -
ri
is a string -
lo
is a string -
ro
is a string
-
Description
join
is used to join the strings in a list into a single string, optionally with separators and a custom string transformation.
L
is the list of strings to combine. Optionally, a function f
can be provided to transform the strings before they are inserted into the output string. If provided, this function must accept a string and return a string.
sep
is the separator used between strings. If omitted, this defaults to a comma and a space. If supplied, the strings li
and ri
will surround each individual part on the left and the right, respectively. Finally, if supplied, the strings lo
and ro
will surround the complete output string from the left and the right.
Examples
L ≔ '("cat", "dog", "rat", "rabbit", "guinea pig")
cat dog rat rabbit guinea pig
join(L)
cat, dog, rat, rabbit, guinea pig
join(L, UpperCase)
CAT, DOG, RAT, RABBIT, GUINEA PIG
join(L, " ❦ ")
cat ❦ dog ❦ rat ❦ rabbit ❦ guinea pig
join(L, ", ", "'", "'")
'cat', 'dog', 'rat', 'rabbit', 'guinea pig'
join(L, ", ", "'", "'", "[", "]")
['cat', 'dog', 'rat', 'rabbit', 'guinea pig']