

Let’s look at an example: iex> string = " \u0061 \u0301 " "á" iex> String. The String module already provides two functions to obtain them, graphemes/1 and codepoints/1. Graphemes consist of multiple codepoints that are rendered as a single character. The charlist support is mainly included because it is required for some Erlang modules.įor further information, see the official Getting Started Guide.Ĭodepoints are just simple Unicode characters which are represented by one or more bytes, depending on the UTF-8 encoding.Ĭharacters outside of the US ASCII character set will always encode as more than one byte.įor example, Latin characters with a tilde or accents ( á, ñ, è) are typically encoded as two bytes.Ĭharacters from Asian languages are often encoded as three or four bytes. When programming in Elixir, we usually use strings, not charlists.

This allows you to use the notation ?Z rather than ‘Z’ for a symbol.
#ASCII CODEPOINTS CODE#
You can get a character’s code point by using ? iex> ?Z 90 Let’s dig in: iex> 'hełło' iex> "hełło" >ģ22 is the Unicode codepoint for ł but it is encoded in UTF-8 as the two bytes 197, 130. What’s the difference? Each value in a charlist is the Unicode code point of a character whereas in a binary, the codepoints are encoded as UTF-8. Internally, Elixir strings are represented with a sequence of bytes rather than an array of characters.Įlixir also has a char list type (character list).Įlixir strings are enclosed with double quotes, while char lists are enclosed with single quotes. NOTE: Using > syntax we are saying to the compiler that the elements inside those symbols are bytes. This trick can help us view the underlying bytes of any string. Let’s look at an example: iex> string = > "hello" iex> string >īy concatenating the string with the byte 0, IEx displays the string as a binary because it is not a valid string anymore.

Elixir strings are nothing but a sequence of bytes.
