How to write a unicode symbol in lua

前端 未结 4 1412
囚心锁ツ
囚心锁ツ 2020-12-20 16:57

How can I write a Unicode symbol in lua. For example I have to write symbol with 9658
when I write

string.char( 9658 );

I got an error.

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-20 17:49

    Lua does not look inside strings. So, you can just write

    mychar = "►"
    

    (added in 2015)

    Lua 5.3 introduced support for UTF-8 escape sequences:

    The UTF-8 encoding of a Unicode character can be inserted in a literal string with the escape sequence \u{XXX} (note the mandatory enclosing brackets), where XXX is a sequence of one or more hexadecimal digits representing the character code point.

    You can also use utf8.char(9658).

提交回复
热议问题