本帖最后由 acdd 于 2016-5-25 03:18 PM 编辑
function ZhuanALaBoShuZi(MeiYouXie)
--中文转阿拉伯数字,好象论坛上有,所以偶木有写。。。
end
function DuoShao(RiQi, DanWeiMingCheng)
local WeiZhi, ZhongWenShuZi;
WeiZhi = string.find(RiQi, DanWeiMingCheng);
if (WeiZhi == nil) then
return RiQi, 0;
end
ZhongWenShuZi = string.sub(RiQi, 1, WeiZhi - 1);
RiQi = string.sub(RiQi, WeiZhi + string.len(DanWeiMingCheng));
return RiQi, ZhuanALaBoShuZi(ZhongWenShuZi);
end
function ZhuanHuan(RiQi)
local Miao, DanWeiMingCheng, DanWeiShuZhi, MeiDanWeiMiaoShu;
local i;
DanWeiMingCheng = {"天", "小时", "分", "秒"};
--不能转带年和月的。偶不会写。。
MeiDanWeiMiaoShu = {3600 * 24, 3600, 60, 1}
Miao = 0;
for i = 1, #DanWeiMingCheng do
RiQi, DanWeiShuZhi = DuoShao(RiQi, DanWeiMingCheng);
Miao = Miao + DanWeiShuZhi * MeiDanWeiMiaoShu;
end
return Miao;
end
print(ZhuanHuan("二天十六小时二十六分九秒")) -- 输出的是231969,貌似是对的。。 |