As we mentioned in the introduction, strings are binaries. In this recipe, we will use the binary concatenation operator (
<>) to join strings.
In this recipe, we will use an IEx session, so let's start it by entering
iex in our command line.
To join (concatenate) two strings, follow these steps:
iex(1)> string_one = "Hello" "Hello"
iex(2)> string_two = "World" "World"
iex(3)> string_one <> string_two "HelloWorld"
iex(4)> string_one <> " " <> string_two <> "!" "Hello World!"
Kernel module defines a macro to concatenate two binaries. Think of this macro as a
<> operator that works by appending the binary defined ...