函数:utf8.codes 获取字符编码

函数名称:获取字符编码

函数功能:返回字符串中每个字符的编码

函数方法

or index,code in utf8.codes(str) do --body end

参数 类型 必填 说明
str string 输入的字符串
返回值 类型 说明
index number 字符位置(按字节数)
code number 字符编码

函数用例

str = "触动精灵"
for index,code in utf8.codes(str) do 
    dialog(string.format("%s的unicode编码为\\u%0x",index,code),5)
end

注意事项

  • 返回字符位置按字节数计算。
  • 如果处理到一个不合法的字节序列,将抛出一个错误。
Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""