In the Elixir documentation it says that you can use the following escapes:
\xNN
- A byte represented by the hexadecimal NN
\uNNNN
- A Unicode code point represented by NNNN
So what if I want to escape a codepoint that's longer than 4 hex digits, i.e. is outside the Basic Multilingual Plane, like 🚒 U+1f692 FIRE ENGINE
or all the Private Use characters?
There is one syntax that is not described on that page:
"\u{1f692}"
You can also use a binary: <<0x1f692::utf8>>
iex> cp = 0x1f692
iex> "Nee #{<<cp::utf8>>} naw"
"Nee 🚒 naw"
Or put it in a charlist [0x1f692]
:
iex> "Nee #{[cp]} naw"
"Nee 🚒 naw"
Both of these are useful if you have the codepoint in a variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With