[tintin++]中文数字转换
写了一天,比较乱,本想使用python脚本来写的想想windows和linux上的python环境不一致,就没用了。#function tolist {
#var list {{一}{1}{二}{2}{三}{3}{四}{4}{五}{5}{六}{6}{七}{7}{八}{8}{九}{9}{十}{10}{百}{100}{千}{1000}{万}{10000}};
#var i 0;
#var num {};
#parse %1 tmp {
#if {$i < 1} {
#var tmp2 $tmp;
#math i {$i + 1};
};
#else {
#var tmp2 $tmp2$tmp;
#var i 0;
#var num {$num$tmp2;};
};
};
#foreach $num t {
#list result add $list.$t;
};
};
#function delzero {
#var result %1;
#replace result {零} {};
};
#function tonum {
#var tmp %1;
#replace tmp {"} {};
#list tmp size len;
#math result 0;
#loop {1} {$len} {i} {
#math j {$i % 2};
#if {$j} {
#math tmp1 {$tmp.$i};
#if {$i < $len} {
#math k {$i + 1};
#math tmp2 {$tmp.$k};
#if {$tmp1 == 10} {#math tmp3 {$tmp1 + $tmp2}};
#else {#math tmp3 {$tmp1 * $tmp2}};
};
#else {
#math tmp3 $tmp1;
};
#math result {$result + $tmp3};
};
};
}
#function convert {
#var chs %1;
#var chs @delzero{$chs};
#regexp $chs {%*万%*} {
#var chs1 @tolist{&1};
#var chs1 @tonum{"$chs1"};
#math num1 {$chs1 * 10000};
#if {"&2" == ""} {
#var result $num1;
};
#else {
#var chs2 @tolist{&2};
#var num2 @tonum{"$chs2"};
#math result {$num1 + $num2};
};
} {
#var chs @tolist{$chs};
#var result @tonum{"$chs"};
};
}
使用方法
#showme @convert{九千九百九十九万九千九百九十九}
北大侠客行MUD,中国最好的MUD
页:
[1]