4

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?

Ken White
  • 123,280
  • 14
  • 225
  • 444
Boris Verkhovskiy
  • 14,854
  • 11
  • 100
  • 103

2 Answers2

4

There is one syntax that is not described on that page:

"\u{1f692}"
Amadan
  • 191,408
  • 23
  • 240
  • 301
1

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.

Adam Millerchip
  • 20,844
  • 5
  • 51
  • 74