Is there any Lua library that converts a string to bytes using UTF8 encoding?

前端 未结 3 1643
Happy的楠姐
Happy的楠姐 2021-02-14 10:28

I wonder whether this kind of library exists.

3条回答
  •  灰色年华
    2021-02-14 11:04

    Lua strings are a sequence of bytes. When you store UTF8 text in them, you're already storing "UTF8 bytes". You can get the bytes like with all other strings, using string.byte(s,i,j):

    local bytes = { string.byte(unicodeString, 1,-1) }
    

    Now bytes is a table containing your "UTF8 bytes". More information about string.byte and UTF8 in Lua is available at:

    Standard Lua string library

    Lua 5.3 standard utf8 library

    Presentation by Roberto Ierusalimschy (one of the creators of Lua) on the future of Lua, which talks about many things and one of them is UTF8 support. It was released before UTF8 support was built into Lua.

提交回复
热议问题