Strings, sigils and binaries
A string in Elixir is a binary of UTF-8 bytes, and that one fact explains most of what surprises a beginner: length counts graphemes, byte_size counts bytes, and a pattern can match a binary at a byte.
The chapter goes from the String functions and the sigils to the bitstring syntax and the charlists that come from Erlang, then to Unicode and the graphemes a reader counts, to the building of a long string without copying it on every step, and to the regular expressions of the standard library.
7.1
Advanced strings in Elixir
heredocs, graphemes against bytes, trim and pad, and inspect
Open
7.2
Sigils
s, c, w, r and D, the delimiter that fits, and the modifier that changes the value
Open
7.3
Binaries and charlists
the bitstring literal, the byte pattern, and a binary matched in a function head
Open
7.4
Charlists
a list of code points, the ~c sigil, and the Erlang functions that want one
Open
7.5
Unicode and encoding
UTF-8 bytes, normalization, and the sort that surprises a reader
Open
7.6
Building strings
interpolation, iodata_to_binary, and why a join beats an addition
Open
7.7
Regular expressions
the ~r sigil, run, scan and replace, and a named capture
Open