本帖最后由 WHY 于 2016-5-25 16:14 编辑
改一下,支持最大有效数值位数为16,不支持小数- @if (0)==(0) echo off
- cscript //nologo //e:jscript "%~f0" < a.txt
- pause & goto :EOF
- @end
-
- var chs = '零一二三四五六七八九十百千万十百千亿十百千万十百千';
- var str = WSH.StdIn.ReadAll().replace(
- /"(?:0+)?(\d{1,16})"/g,
- function(s0, s1){
- var len = s1.length;
- s1 = s1.replace(/\d/g,
- function(s0){
- s0 = chs.substr(s0, 1) + (len > 1 ? chs.substr(len + 8, 1) : ''); len--;
- return s0;
- }
- )
- s1 = s1.replace(/零[千百十]/g, '零');
- s1 = s1.replace(/亿零+万/, '亿零').replace(/零+([亿万])/g, '$1');
- s1 = s1.replace(/零+/g, '零').replace(/(.)零$/, '$1');
- return '"' + s1 + '"';
- }
- )
-
- WSH.Echo(str)
复制代码
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
C:\Users\Administrator>cd /d D:\Test
D:\Test>type a.txt
"100","9000901000008402"
"43210","1002506"
"00001", "0000"
"543210001"
D:\Test>test.bat
"一百","九千万九千零一十亿零八千四百零二"
"四万三千二百一十","一百万二千五百零六"
"一", "零"
"五亿四千三百二十一万零一"
请按任意键继续. . .
D:\Test> |