...

/

String Representation in Elixir

String Representation in Elixir

Let’s explore the properties of strings further, including some string traps.

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

Press + to interact
<<?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 matched in ...