Erlang Central

String Join

Revision as of 21:53, 18 August 2006 by Cyberlync (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Problem

You need to combine several strings into a larger string.

Solution

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.