All lessons

Working with Text

7 min · Elixir

Join strings, measure them, and embed values with interpolation.

Elixir · Working with Text0/5 cleared

Enemy 1 of 5

Strings are binaries

This code joins two strings with the <> operator and prints the result. Press Run to see Hello, Ada.

Why this works

Elixir strings are UTF-8 encoded binaries under the hood. You don't need to think about that detail day-to-day, but it explains why string operations in Elixir are consistently fast and why Elixir handles international text correctly by default. Day-to-day, a string is just text wrapped in double quotes, same as most languages.

Two strings are joined end-to-end with `<>`, the concatenation operator, deliberately distinct from `+`, which is reserved for numbers. This is a small but useful design choice: in Elixir, `+` and `<>` can never be confused with each other, unlike languages that overload `+` to mean both "add" and "concatenate" depending on the types involved.

You
Packet Wolf
Loading editor…
Sign up to fightThis one runs on our servers, so it needs a free account.