Search⌘ K
AI Features

String Representation in Elixir

Explore how Elixir handles strings as binaries and bitstrings, understand the use of the <<>> operator, code points, and common string traps like slow concatenation and memory leaks. Gain insights into best practices for managing strings and optimizing performance in your Elixir applications.

We'll cover the following...

Strings are binaries

Elixir has datatypes and libraries for dealing with strings of data called bitstrings. A bitstring that’s a multiple of 8 bits is a binary. The operator for converting something to a bitstring is << >>. We can see them at work, like this:

Executable

C++
<<?C, ?A, ?B>>

Output

iex(1)> <<?C, ?A, ?B>>
"CAB"

While the <<>> operator looks like a sharp tool that could hurt us, we don’t have to worry. It’s a binary, and the most common Elixir strings are binaries manipulated and ...