How to join strings in Elixir?

thiagofm picture thiagofm · Dec 29, 2013 · Viewed 71.9k times · Source

How do I join two strings in a list with a space, like:

["StringA", "StringB"]

becomes

"StringA StringB"

Answer

thiagofm picture thiagofm · Dec 29, 2013

If you just want to join some arbitrary list:

"StringA" <> " " <> "StringB"

or just use string interpolation:

 "#{a} #{b}"

If your list size is arbitrary:

Enum.join(["StringA", "StringB"], " ")

... all of the solutions above will return

"StringA StringB"