Erlang Central

String Join

From ErlangCentral Wiki


You need to combine several strings into a larger string.


The built-in concatenation operator (++) is the de-facto answer here:

1> "Some " ++ "text " ++ "and" ++ " stuff".
"Some text and stuff"

You can also use the lists:append function:

2> lists:append(["Some ", "text ", "and", " stuff"]).
"Some text and stuff"

++ and lists:append will always allocate a new string.

If you want to join several strings together using a separator, you can use string:join/2:

For example:

3> string:join(["one", "two", "three"], ", ").
"one, two, three"