utf8.escape()

类型 函数
utf8.*
返回值 字符串
版本 发行版 2024.3703
关键字 utf8、UTF-8、Unicode、字符串、转义

概览

将带有转义序列的字符串转换为UTF-8格式的字符串。支持几种转义格式

格式 说明
%n n 是数字 Unicode 代码点
%{n} %n 相同,但带有花括号
%un %n 相同;u 代表“Unicode”
%u{n} %{n} 相同;u 代表“Unicode”
%xh 十六进制数
%x{h} %xh 相同,但带有花括号
%? ? 代表任何其他字符:转义此字符

语法

utf8.escape( s )
s (必需)

字符串. 要转换的字符串。

示例

local utf8 = require( "plugin.utf8" )

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

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