中文数字转阿拉伯数字 Autohotkey

释放双眼,带上耳机,听听看~!

本脚本来自于Thinkai的博客,仅作为归档。

conv2num(str){
d := {"零":0,"一":1,"二":2,"两":2,"三":3,"四":4,"五":5,"六":6,"七":7,"八":8,"九":9,"十":10,"百":100,"千":1000,"万":10000,"亿":100000000}
n = 0
 
a := StrSplit(str,"亿")
if a[2]
{
    b := StrSplit(a[2],"万")
    s1 := a[1],s2 := b[1], s3 := b[2]
}
else
{
    a := StrSplit(str,"万")
    s1 := a[1],s2 := a[2], s3 := ""
}
l1 := InStr(str,"亿") ? d["亿"] : (InStr(str,"万") ? d["万"] : 1)
l2 := InStr(a[2],"万") ? d["万"] : (a[2] ? 1 : 0)
l3 := b[2] ? 1 : 0
if l1=1
{
    Loop
    {
        if !str
            break
        if RegExMatch(str,"^(一|二|两|三|四|五|六|七|八|九)(十|百|千|)(.*)",m)
        {
            t := d[m1] * (m2 ? d[m2] : 1)
            n += t, str := m3
        }
        else if RegExMatch(str,"^十(一|二|两|三|四|五|六|七|八|九|)$",m)
        {
            t := 10 + (m1 ? d[m1] : 0)
            n += t, str := ""
        }
        else if RegExMatch(str,"^零(.*)",m)
            str := m1
    }
}
else
    n := conv2num(s1)*l1 + conv2num(s2)*l2 + conv2num(s3)*l3
return n
}

 

人已赞赏
AHKV1

上传文件到网站 POST Autohotkey

2020-2-21 15:10:03

AHKV1

运行快捷方式 runlink Autohotkey

2020-2-21 15:11:32

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索