edf 发表于 2023-9-18 13:59:37

【tintin++】中文数字转阿拉伯数字

本帖最后由 edf 于 2023-9-18 02:02 PM 编辑

#class texttofigur open;

#var texttofigur_1 0;
#var texttofigur_2 0;
#function texttofigur {
    #var texttofigur_1 = %1;
    #var texttofigur_2 0;
    #regexp $texttofigur_1 {九百} {#math texttofigur_2 $texttofigur_2+900;#REPLACE texttofigur_1 {九百} {}};
    #regexp $texttofigur_1 {八百} {#math texttofigur_2 $texttofigur_2+800;#REPLACE texttofigur_1 {八百} {}};
    #regexp $texttofigur_1 {七百} {#math texttofigur_2 $texttofigur_2+700;#REPLACE texttofigur_1 {七百} {}};
    #regexp $texttofigur_1 {六百} {#math texttofigur_2 $texttofigur_2+600;#REPLACE texttofigur_1 {六百} {}};
    #regexp $texttofigur_1 {五百} {#math texttofigur_2 $texttofigur_2+500;#REPLACE texttofigur_1 {五百} {}};
    #regexp $texttofigur_1 {四百} {#math texttofigur_2 $texttofigur_2+400;#REPLACE texttofigur_1 {四百} {}};
    #regexp $texttofigur_1 {三百} {#math texttofigur_2 $texttofigur_2+300;#REPLACE texttofigur_1 {三百} {}};
    #regexp $texttofigur_1 {二百} {#math texttofigur_2 $texttofigur_2+200;#REPLACE texttofigur_1 {二百} {}};
    #regexp $texttofigur_1 {一百} {#math texttofigur_2 $texttofigur_2+100;#REPLACE texttofigur_1 {一百} {}};
    #regexp $texttofigur_1 {九十} {#math texttofigur_2 $texttofigur_2+90;#REPLACE texttofigur_1 {九十} {}};
    #regexp $texttofigur_1 {八十} {#math texttofigur_2 $texttofigur_2+80;#REPLACE texttofigur_1 {八十} {}};
    #regexp $texttofigur_1 {七十} {#math texttofigur_2 $texttofigur_2+70;#REPLACE texttofigur_1 {七十} {}};
    #regexp $texttofigur_1 {六十} {#math texttofigur_2 $texttofigur_2+60;#REPLACE texttofigur_1 {六十} {}};
    #regexp $texttofigur_1 {五十} {#math texttofigur_2 $texttofigur_2+50;#REPLACE texttofigur_1 {五十} {}};
    #regexp $texttofigur_1 {四十} {#math texttofigur_2 $texttofigur_2+40;#REPLACE texttofigur_1 {四十} {}};
    #regexp $texttofigur_1 {三十} {#math texttofigur_2 $texttofigur_2+30;#REPLACE texttofigur_1 {三十} {}};
    #regexp $texttofigur_1 {二十} {#math texttofigur_2 $texttofigur_2+20;#REPLACE texttofigur_1 {二十} {}};
    #regexp $texttofigur_1 {一十} {#math texttofigur_2 $texttofigur_2+10;#REPLACE texttofigur_1 {一十} {}};
    #regexp $texttofigur_1 {十} {#math texttofigur_2 $texttofigur_2+10;#REPLACE texttofigur_1 {十} {}};
    #regexp $texttofigur_1 {九} {#math texttofigur_2 $texttofigur_2+9;#REPLACE texttofigur_1 {九} {}};
    #regexp $texttofigur_1 {八} {#math texttofigur_2 $texttofigur_2+8;#REPLACE texttofigur_1 {八} {}};
    #regexp $texttofigur_1 {七} {#math texttofigur_2 $texttofigur_2+7;#REPLACE texttofigur_1 {七} {}};
    #regexp $texttofigur_1 {六} {#math texttofigur_2 $texttofigur_2+6;#REPLACE texttofigur_1 {六} {}};
    #regexp $texttofigur_1 {五} {#math texttofigur_2 $texttofigur_2+5;#REPLACE texttofigur_1 {五} {}};
    #regexp $texttofigur_1 {四} {#math texttofigur_2 $texttofigur_2+4;#REPLACE texttofigur_1 {四} {}};
    #regexp $texttofigur_1 {三} {#math texttofigur_2 $texttofigur_2+3;#REPLACE texttofigur_1 {三} {}};
    #regexp $texttofigur_1 {二} {#math texttofigur_2 $texttofigur_2+2;#REPLACE texttofigur_1 {二} {}};
    #regexp $texttofigur_1 {一} {#math texttofigur_2 $texttofigur_2+1;#REPLACE texttofigur_1 {一} {}};
   

    #nop 最低一件。
    #if {"$texttofigur_2"=="0"} {#var texttofigur_2 1};
    #RETURN {$texttofigur_2};
}




#class texttofigur close;转换范围是九百九十九以内,没有输入默认返回1
虽然是无意为之,但这个函数的好处是自动忽略“件”、“枚”之类的量词,只返回阿拉伯数字

应该有更好写法但我大脑过载懒得动了


页: [1]
查看完整版本: 【tintin++】中文数字转阿拉伯数字