本帖最后由 aloha20200628 于 2024-3-27 11:41 编辑
回复 1# IGOfilm
以下代码存为test.bat,在记事本中编码选择ansi(简中编码);
一楼示例文件存为1.txt,在记事本中编码选择ansi(简中编码);
转换结果文件为1.new.txt
代码中子过程CnToAn9999的转换能力上限=9999,本脚本基于示例文件设定001-999- @echo off &setlocal enabledelayedexpansion
- (for /f "tokens=1* delims=第卷" %%1 in (1.txt) do (
- (call :CnToAn9999 %%1 n)
- set "n=00!n!"&echo,第!n:~-3!卷%%2
- ))>1.new.txt
- exit/b
- :CnToAn9999 // %1=中文数字符串(实值) %2=返回值变量名
- if "%~1"=="零" set "%~2=0"&exit/b
- set "cn#=%~1"&set "cn#=!cn#:零=!"&set "uList=十,百,千"
- set/a "n#=0,一=1,二=2,三=3,四=4,五=5,六=6,七=7,八=8,九=9,十=10,百=100,千=1000"
- for /L %%k in (0, 2, 6) do if "!cn#:~%%k,1!" neq "" (
- set "n2c=!cn#:~%%k,2!" &set "nc1=!n2c:~0,1!" &set "nc2=!n2c:~1,1!"
- if "!nc2!"=="" (set/a n#+=!nc1!) else for %%c in (!nc2!) do (
- if "!uList:%%c=!" neq "!uList!" (set/a n#+=!nc1!*!nc2!) else (set/a n#+=!nc1!+!nc2!)
- )
- )
- set "%~2=!n#!" &exit/b
复制代码
|