是开碧落 发表于 2011-2-6 23:14:24

中文数字转阿拉伯数字的触发

别名 char2int
#var %2 0;#var lchar %1;lchar=%remove("零",@lchar);lchar=%replace(@lchar,一,1);lchar=%replace(@lchar,二,2);lchar=%replace(@lchar,三,3);lchar=%replace(@lchar,四,4);lchar=%replace(@lchar,五,5);lchar=%replace(@lchar,六,6);lchar=%replace(@lchar,七,7);lchar=%replace(@lchar,八,8);lchar=%replace(@lchar,九,9);lchar=%replace(@lchar,十,0|);lchar=%replace(@lchar,百,00|);lchar=%replace(@lchar,千,000|);lchar=%replace(@lchar,万,0000|);#forall (@lchar) {#if (%i=0) {lcharn=%concat(1,%i)} {lcharn=%i};#add %2 @lcharn}

触发行:
^研究次数最少一次,最多也不能超过(%c)次。
命令行:
char2int %1 numyy

=======
用途: 如果你身上装备有变化, 又想最大次数研究练习次数等
就可以在更换完装备以后, numyy=5000 赋值一个肯定超过最大次数的数值
然后yanjiu xxx @numyy, 自动切出最大研究次数
练习, 学习 同

xiaoxiao 发表于 2011-4-22 22:51:04

有个bug
1012次(中文的)
解析成1002次

是开碧落 发表于 2011-8-5 12:00:16

研究次数最少一次,最多也不能超过一千零十四次。

已修正

天书奇侠 发表于 2012-1-5 22:52:25

#fu t1 {%eval(%replace(%replace(%replace(0+%replace(%replace(%replace(%replace(%replace(%replace(%replace(%replace(%replace(%replace(%replace(%replace(%replace(%1,"零","0+"),"十","*10+"),"百","*100+"),"千","*1000+"),"六","6"),"一","1"),"二","2"),"三","3"),"四","4"),"五","5"),"七","7"),"八","8"),"九","9")+0),"++","+"),"+*","+"))}

#fu t2 {%if(%pos(万,%1),%eval(@t1(%word(%1,1,万))*10000+@t1(%word(%1,2,万))),@t1(%1))}


一万以内用@ti(%1)
一亿以内用@t2(%1)

gameboy 发表于 2015-11-18 21:20:24

天书的说 没看懂

gumuyuan 发表于 2015-11-30 17:05:11

超过100万的时候果然会有问题

萧云晨 发表于 2017-1-7 00:27:50

Mush 中文数字转阿拉伯数字 的 函数

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

iqihz 发表于 2018-4-3 11:11:56

本帖最后由 iqihz 于 2018-4-3 11:38 编辑

这个不是百万,超过十万就识别不出来了
稍微做了点修改

#var %2 0;#var lchar %1;lchar=%remove("零",@lchar);lchar=%replace(@lchar,一,1);lchar=%replace(@lchar,二,2);lchar=%replace(@lchar,三,3);lchar=%replace(@lchar,四,4);lchar=%replace(@lchar,五,5);lchar=%replace(@lchar,六,6);lchar=%replace(@lchar,七,7);lchar=%replace(@lchar,八,8);lchar=%replace(@lchar,九,9);lchar=%replace(@lchar,十,0|);lchar=%replace(@lchar,百,00|);lchar=%replace(@lchar,千,000|);lchar=%replace(@lchar,万,|万|);lchar=%replace(@lchar,亿,|亿|);lchar=%replace(@lchar,||,|);multiply=1;#if %pos(万,@lchar) {multiply=10000};#if %pos(亿,@lchar) {multiply=100000000};#forall (@lchar) {#if (%i=0) {lcharn=%concat(1,%i);lcharn=[@lcharn*@multiply]} {lcharn=[%i*@multiply];#if %pos(亿,%i) {multiply=10000;lcharn=0};#if %pos(万,%i) {multiply=1;lcharn=0}};#add %2 @lcharn}

增加了个判断,理论上能识别到9千亿,不过zmud数值二十一亿四千多就溢出了


页: [1]
查看完整版本: 中文数字转阿拉伯数字的触发