types.String.join
Joins the items of arr into one string, with str between each pair.
... from the prose below, not from the signature.Parameters
arr | array | array of items to join; each is converted with tostring() |
filter | bool|function | selects which items are kept; see Notes optional |
... | any | not a real parameter; a third explicit argument throws instead (see Errors) repeats |
Return value
The items of arr, converted with tostring() and joined with str between each pair. An empty arr (or one where every item is filtered out) gives "".
Errors
Throws Too many arguments when called with more than 2 explicit arguments - unlike most methods on this page, join enforces its own upper bound instead of silently ignoring the extra. Throws a type-check error naming array if arr is not an array.
Notes
Takes 1 or 2 arguments: filter is optional. If filter is a bool, true drops every null item and every empty-string item from the result; false (or omitting filter) keeps everything. If filter is a function, it is called once per item and only items for which it returns a truthy value are kept, e.g. function(item) { return item.len() > 1 }.
Example
println("\",\".join([\"a\", \"b\", \"c\"]) =", ",".join(["a", "b", "c"]))
// bool filter: drop null and empty-string items.
println("\",\".join([\"a\", \"\", null, \"b\"], true) =", ",".join(["a", "", null, "b"], true))
// function filter: keep items the predicate accepts.
println("\",\".join([\"a\", \"bb\", \"ccc\"], filter) =", ",".join(["a", "bb", "ccc"], function(item) { return item.len() > 1 }))",".join(["a", "b", "c"]) = a,b,c
",".join(["a", "", null, "b"], true) = a,b
",".join(["a", "bb", "ccc"], filter) = bb,cccSee also
concat | Joins its arguments into one string, with str between each pair. |
split | Splits str into an array of strings. |
| string | class index |