简体   繁体   English

转义 5 或 6 十六进制数字 Unicode 代码点

[英]Escape 5 or 6 hex digit Unicode codepoint

In the Elixir documentation it says that you can use the following escapes:Elixir 文档中,它说您可以使用以下转义符:

  • \xNN - A byte represented by the hexadecimal NN \xNN - 由十六进制NN表示的字节
  • \uNNNN - A Unicode code point represented by NNNN \uNNNN - 由NNNN表示的 Unicode 代码点

So what if I want to escape a codepoint that's longer than 4 hex digits, ie is outside the Basic Multilingual Plane, like U+1f692 FIRE ENGINE or all the Private Use characters?那么,如果我想转义一个超过 4 个十六进制数字的代码点,即在基本多语言平面之外,如U+1f692 FIRE ENGINE或所有私人使用字符,该怎么办?

There is one syntax that is not described on that page:该页面上没有描述一种语法:

"\u{1f692}"

You can also use a binary: <<0x1f692::utf8>>您还可以使用二进制文件: <<0x1f692::utf8>>

iex> cp = 0x1f692
iex> "Nee #{<<cp::utf8>>} naw"
"Nee 🚒 naw"

Or put it in a charlist [0x1f692] :或者将其放入[0x1f692]中:

iex> "Nee #{[cp]} naw"
"Nee 🚒 naw"

Both of these are useful if you have the codepoint in a variable.如果您在变量中有代码点,那么这两种方法都很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM