String Join

From Erlang Community

(Difference between revisions)
Revision as of 21:53, 18 August 2006 (edit)
Cyberlync (Talk | contribs)

← Previous diff
Revision as of 21:52, 3 September 2006 (edit) (undo)
Bfulgham (Talk | contribs)

Next diff →
Line 20: Line 20:
-[[Category:CookBook]]+[[Category:CookBook]][[Category:StringRecipes]]

Revision as of 21:52, 3 September 2006

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.

Erlang/OTP Projects
Personal tools