mush怎么用lua脚本把中文数字转化成阿拉伯数字?
【 经 验 】一亿九千七百九十三万七千五百零七像这样的怎么弄呢?
北大侠客行MUD,中国最好的MUD http://pkuxkx.com/forum/thread-22782-1-1.html
把那些zmud函数用代码表示就ok了。。。 从别人的脚本里面偷一个
function chs2num(s)----------------数字转换
local cur = 0
local yi = 0
local sgl = 0
local len = string.len(s)
local tt = {}
tt["零"] = function() end
tt["一"] = function() sgl = 1 end
tt["二"] = function() sgl = 2 end
tt["三"] = function() sgl = 3 end
tt["四"] = function() sgl = 4 end
tt["五"] = function() sgl = 5 end
tt["六"] = function() sgl = 6 end
tt["七"] = function() sgl = 7 end
tt['八'] = function() sgl = 8 end
tt["九"] = function() sgl = 9 end
tt["十"] = function()
if sgl == 0 then sgl = 1 end
cur = cur + sgl * 10
sgl = 0
end
tt["百"] = function()
cur = cur + sgl * 100
sgl = 0
end
tt["千"] = function()
cur = cur + sgl * 1000
sgl = 0
end
tt["万"] = function()
cur = (cur +sgl) * 10000
sgl = 0
end
tt["亿"] = function()
yi = (cur + sgl) * 100000000
cur = 0
sgl = 0
end
for i = 1,len,2 do
k = string.sub(s,i,i+1)
tt()
end
num = yi + cur +sgl
---- print(num)
return num
end 恩,楼上的代码不错。终于搞定这个问题了。 function chinese_to_number(str)
if (#str % 2) == 1 then
str = string.sub(str,1,#str-1);
end
result=0
wan=1
unit=1
for i=#str -2 ,0,-2 do
char=string.sub(str,i+1,i+2)
if (char=="十") then
unit=10*wan
if (i==0) then
result=result+unit
elseif _nums==nil then
result=result+unit
end
elseif (char=="甲" and string.sub(str,i+3,i+4)=="子") then
unit=60*wan
wan=60
elseif (char=="百") then
unit=100*wan
elseif (char=="千") then
unit=1000*wan
elseif (char=="万") then
unit=10000*wan
wan=10000
else
if _nums~=nil then
result=result+_nums*unit
end
end
end
return result
end
页:
[1]