zmud之汉字转换为数字

这是一个普遍的需求,希望记录统计一共获得多少武学和道行等,以数字形式表现,方便计算。

由于zmud版本的不同,支持的函数有所差异。目前讨论zmud4.62和5.55版本的实现。

 

Trigger实例:

 #tri ^你灭妖得到了(*)点潜能!
{convertnumber %1
#add reward_qn %number(@in_chinese_number)
#say 此次连线灭妖共获得@reward_qn点潜能,共@reward_guai个怪,平均每个怪[@reward_qn/@reward_guai]点潜能
#color white}

 

相关alias定义:

#alias reward_init {#var reward_guai 0;#var reward_wx 0;#var reward_qn 0;#var reward_time {%time()} {%time()}

 

#alias reward {#say 此次连线登陆时间@reward_time,灭妖共@reward_guai个怪,,共获得@reward_qn点潜能,平均每个怪[@reward_qn/@reward_guai]点潜能,共获得@reward_wx点武学,平均每个怪[@reward_wx/@reward_guai]点武学}

#alias convertnumber {#var in_chinese_number %1;#read cmd_digit.txt;#var in_chinese_number @out_number;#say @in_chinese_number}

 

测试:

convertnumber 一万零五百二十一

将显示 10521

 

最主要的cmd_digit.txt实现由于4.62和5.55版本函数的差异分别实现:

4.62版本 cmd_digit.txt

#var chinese_number_list {零|一|二|三|四|五|六|七|八|九|十|百|千|万} #var number_list {|1|2|3|4|5|6|7|8|9|A|B|C|D} #var ix 0 #alias item {#var tmp_n 0;#ForAll %1 {#add tmp_n 1;#if (@tmp_n=%2) {#var myitem %i}}} #FORALL @chinese_number_list {#add ix 1;item @chinese_number_list @ix;#var tmp_chinese @myitem;item @number_list @ix;#var tmp_number @myitem;#var in_chinese_number %replace(@in_chinese_number,@tmp_chinese,@tmp_number);} #if !%isnumber(%copy(@in_chinese_number,1,1)) {#var in_chinese_number %insert(1,@in_chinese_number,1)} #var tmp_len %len(@in_chinese_number); #var out_number 0; #Loop @tmp_len {#var tmp_word %copy(@in_chinese_number,%{i},1);#if (%isnumber(@tmp_word)) {#if (%i<@tmp_len) {#var tmp_n %copy(@in_chinese_number,(%i+1),1);#if (@tmp_n=A) {#var tmp_n 1};#if (@tmp_n=B) {#var tmp_n 2};#if (@tmp_n=C) {#var tmp_n 3};#if (@tmp_n=D) {#var tmp_n 4};#case (%eval(@tmp_n)) {#add out_number (%number(@tmp_word)*10)} {#add out_number (%number(@tmp_word)*100)} {#add out_number (%number(@tmp_word)*1000)} {#add out_number (%number(@tmp_word)*10000)}} {#add out_number %number(@tmp_word)}}}; #var in_chinese_number @out_number #say @in_chinese_number #unvar tmp_len #unvar chinese_number_list #unvar number_list #unvar ix


5.55版本(4.62版本是通用版本,即在5.55版本中也可以用上面的代码)cmd_digit.txt

 

#var chinese_number_list {零|一|二|三|四|五|六|七|八|九|十|百|千|万} #var number_list {|1|2|3|4|5|6|7|8|9|A|B|C|D} #var ix 0 #FORALL @chinese_number_list {#add ix 1;#var in_chinese_number %replace(@in_chinese_number,%item(@chinese_number_list,@ix),%item(@number_list,@ix));} #if !%isnumber(%copy(@in_chinese_number,1,1)) {#var in_chinese_number %insert(1,@in_chinese_number,1)} #var tmp_len %len(@in_chinese_number); #var out_number 0; #Loop @tmp_len {#var tmp_word %copy(@in_chinese_number,%{i},1);#if (%isnumber(@tmp_word)) {#if (%{i}<@tmp_len) {#var tmp_n %copy(@in_chinese_number,(%{i}+1),1);#case (%ascii(@tmp_n)-%ascii(A)+1) {#add out_number (%number(@tmp_word)*10)} {#add out_number (%number(@tmp_word)*100)} {#add out_number (%number(@tmp_word)*1000)} {#add out_number (%number(@tmp_word)*10000)}} {#add out_number %number(@tmp_word)}}}; #var in_chinese_number @out_number #unvar tmp_len #unvar chinese_number_list #unvar number_list #unvar ix

 

cmd_digit.txt放在zmud.exe的所在的目录下。

 

你可能感兴趣的:(zmud之汉字转换为数字)