getmetatable("").__index = function(str, i)
return string.sub(str,i,i)
end
---test
local array = {
['0']='零',
['1']='一',
['2']='二',
['3']='三',
['4']='四',
['5']='五',
['6']='六',
['7']='七',
['8']='八',
['9']='九',
['+'] = '加',
['-'] = '减',
}
local n = -9876543210
local s = tostring(n)
local result = ""
for i = 1, #s do
local index = s[i]
local c = array[index]
result=result..c
end
print(type(result), result)
---out
string 减九八七六五四三二一零
网友评论