在lua中代表单字符的方式是什么 [英] what is the way to represent a unichar in lua

查看:79
本文介绍了在lua中代表单字符的方式是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我需要使用以下python值,请使用unicode char'0':

If I need to have the following python value, unicode char '0':

>>> unichr(0)
u'\x00'

如何在Lua中定义它?

How can I define it in Lua?

推荐答案

如何

function unichr(ord)
    if ord == nil then return nil end
    if ord < 32 then return string.format('\\x%02x', ord) end
    if ord < 126 then return string.char(ord) end
    if ord < 65539 then return string.format("\\u%04x", ord) end
    if ord < 1114111 then return string.format("\\u%08x", ord) end
end

这篇关于在lua中代表单字符的方式是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆