Erlang Central

Difference between revisions of "String Join"

From ErlangCentral Wiki

 
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.