LFE Friday - string:join/2
This week's LFE Friday was translated with permission from the Erlang Thursday series by Steven Proctor. This week's translator: Robert Virding.
Today's LFE Friday is on string:join/2.
string:join/2
takes a list of strings as its first argument, and a string separator used to join the strings together into a single string.
> (string:join '("a" "b" "c") "")
"abc"
> (string:join '("a" "b" "c") "-")
"a-b-c"
The separator string can be a string of any length, and doesn't just have to be a single character.
> (string:join '("a" "b" "c") "___")
"a___b___c"
> (string:join '("a" "b" "c") " ")
"a b c"
And as with any string, a list of characters, or even integers, can be used as the separator string.
> (string:join '("a" "b" "c") '(#\A))
"aAbAc"
> (string:join '("a" "b" "c") '(52))
"a4b4c"
-Proctor, Robert