May 2018
Intermediate to advanced
412 pages
9h 3m
English
Whereas single-quoted strings are stored as char lists, the contents of a double-quoted string (dqs) are stored as a consecutive sequence of bytes in UTF-8 encoding. Clearly this is more efficient in terms of memory and certain forms of access, but it does have two implications.
First, because UTF-8 characters can take more than a single byte to represent, the size of the binary is not necessarily the length of the string.
| | iex> dqs = "∂x/∂y" |
| | "∂x/∂y" |
| | iex> String.length dqs |
| | 5 |
| | iex> byte_size dqs |
| | 9 |
| | iex> String.at(dqs, 0) |
| | "∂" |
| | iex> String.codepoints(dqs) |
| | ["∂", "x", "/", "∂", "y"] |
| | iex> String.split(dqs, "/") |
| | ["∂x", "∂y"] |
Second, because you’re no longer using lists, you need to learn ...
Read now
Unlock full access