Type Function
Library utf8.*
Return value String
Revision Release 2024.3703
Keywords utf8, UTF-8, Unicode, string, escape


Converts a string with escape sequences to a UTF-8 formatted string. Several escape formats are supported:

Format Description
%n n is a numeric Unicode code point
%{n} same as %n but with braces
%un same as %n; u stands for "Unicode"
%u{n} same as %{n}; u stands for "Unicode"
%xh hexadecimal number
%x{h} same as %xh but with braces
%? ? stands for any other character: escape this character


utf8.escape( s )
s (required)

String. The string to convert.


local utf8 = require( "plugin.utf8" )

local testStr = utf8.escape( "%9825%32%{20320}%u{22909}%xFF0C%x{4E16}%x754C%32%9825" )

print( testStr )  --> ♡ 你好,世界 ♡