Search code examples
elixir

How to join strings in Elixir?


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

["StringA", "StringB"]

becomes

"StringA StringB"

Solution

  • 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"