复制代码
- @echo off
- setlocal EnableDelayedExpansion
- set __yiwuyun.txt=___yiwuyun.txt
- for /f "delims=" %%a in ('type 1.txt') do (
- set "string=%%a"
- echo String Before Parse:!string!
- set "string=!string:零=!"
- call :ParseString
- echo String After Parse: !total!
- )
- exit /b 0
- :ParseString
- call :DisposeYi
- exit /b 0
- :DisposeYi
- setlocal
- call :GetTokenTextNAndCount "^!string^!" "亿"
- if !tokenTextCount! equ 1 (
- call :DisposeWan
- ) else (
- if not "!tokenText1!"=="" if not "!tokenText2!"=="" (
- set string=!tokenText1!
- call :ParseString
- set /a yiLeft=!total!*100000000
- set string=!tokenText2!
- call :ParseString
- set /a total=!total!+!yiLeft!
- )
- if not "!tokenText1!"=="" if "!tokenText2!"=="" (
- set string=!tokenText1!
- call :ParseString
- set /a total=!total!*100000000
- )
- )
- endlocal&set /a total=%total%
- exit /b 0
- :DisposeWan
- setlocal
- call :GetTokenTextNAndCount "^!string^!" "万"
- if !tokenTextCount! equ 1 (
- call :DisposeQian
- ) else (
- if not "!tokenText1!"=="" if not "!tokenText2!"=="" (
- set string=!tokenText1!
- call :ParseString
- set /a wanLeft=!total!*10000
- set string=!tokenText2!
- call :ParseString
- set /a total=!total!+!wanleft!
- )
- if not "!tokenText1!"=="" if "!tokenText2!"=="" (
- set string=!tokenText1!
- call :ParseString
- set /a total=!total!*10000
- )
- )
- endlocal&set /a total=%total%
- exit /b 0
- :DisposeQian
- setlocal
- call :GetTokenTextNAndCount "^!string^!" "千"
- if !tokenTextCount! equ 1 (
- call :DisposeBai
- ) else (
- if not "!tokenText1!"=="" if not "!tokenText2!"=="" (
- set string=!tokenText1!
- call :ParseString
- set /a qianLeft=!total!*1000
- set string=!tokenText2!
- call :ParseString
- set /a total=!total!+!qianLeft!
- )
- if not "!tokenText1!"=="" if "!tokenText2!"=="" (
- set string=!tokenText1!
- call :ParseString
- set /a total=!total!*1000
- )
- )
- endlocal&set /a total=%total%
- exit /b 0
- :DisposeBai
- setlocal
- call :GetTokenTextNAndCount "^!string^!" "百"
- if !tokenTextCount! equ 1 (
- call :DisposeShi
- ) else (
- if not "!tokenText1!"=="" if not "!tokenText2!"=="" (
- set string=!tokenText1!
- call :ParseString
- set /a baiLeft=!total!*100
- set string=!tokenText2!
- call :ParseString
- set /a total=!baiLeft!+!total!
- )
- if not "!tokenText1!"=="" if "!tokenText2!"=="" (
- set string=!tokenText1!
- call :ParseString
- set /a total=!total!*100
- )
- )
- endlocal&set /a total=%total%
- exit /b 0
- :DisposeShi
- setlocal
- call :GetTokenTextNAndCount "^!string^!" "十"
- if !tokenTextCount! equ 1 (
- call :DisposeGe
- ) else (
- if not "!tokenText1!"=="" if not "!tokenText2!"=="" (
- set string=!tokenText1!
- call :ParseString
- set /a shiLeft=!total!*10
- set string=!tokenText2!
- call :ParseString
- set /a shiRight=!total!
- set /a total=!shiLeft!+!shiRight!
- )
- if not "!tokenText1!"=="" if "!tokenText2!"=="" (
- set string=!tokenText1!
- call :ParseString
- set /a total=!total!*10
- )
- if "!tokenText1!"=="" if not "!tokenText2!"=="" (
- set string=!tokenText2!
- call :ParseString
- set /a total=!total!+10
- )
- )
- endlocal&set /a total=%total%
- exit /b 0
- :DisposeGe
- setlocal
- call :ParseDigit !string!
- set /a total=!num!
- endlocal&set /a total=%total%
- exit /b 0
- :ParseDigit
- setlocal
- if "%1"=="零" (
- set /a num=0
- ) else if "%1"=="一" (
- set /a num=1
- ) else if "%1"=="二" (
- set /a num=2
- ) else if "%1"=="三" (
- set /a num=3
- ) else if "%1"=="四" (
- set /a num=4
- ) else if "%1"=="五" (
- set /a num=5
- ) else if "%1"=="六" (
- set /a num=6
- ) else if "%1"=="七" (
- set /a num=7
- ) else if "%1"=="八" (
- set /a num=8
- ) else if "%1"=="九" (
- set /a num=9
- ) else (
- echo 不是中文纯数字符号,解析的结果可能不正确。
- set /a num=0
- )
- endlocal&set /a num=%num%
- exit /b 0
- :GetStringLength
- setlocal
- set string=!string!
- set /a n=0
- :startGetStringLength
- if not "!string!"=="" (
- set string=!string:~1!
- set /a n=!n!+1
- goto startGetStringLength
- )
- set /a stringLength=!n!
- endlocal&set stringLength=%stringLength%
- exit /b 0
- :GetTokenPlaceNAndCount
- setlocal
- set "string=%~1"
- set "secondParameter=%~2"
- call :GetStringLength
- set /a nGetTokenPlaceNAndCount=!stringLength!-1
- set /a nToken=1
- set /a tokenPlace0=-1
- for /l %%a in (0,1,!nGetTokenPlaceNAndCount!) do (
- if "!string:~%%a,1!"=="!secondParameter!" (
- set /a tokenPlace!nToken!=%%a
- set /a nToken+=1
- )
- )
- set /a tokenPlace!nToken!=!stringLength!
- set /a tokenCount=!nToken!-1
- type nul>!__yiwuyun.txt!
- for /l %%a in (0,1,!nToken!) do (
- echo set /a tokenPlace%%a=!tokenPlace%%a!>>!__yiwuyun.txt!
- )
- echo set /a tokenCount=!tokenCount!>>!__yiwuyun.txt!
- endlocal
- for /f "tokens=1 delims=" %%a in ('type !__yiwuyun.txt!') do (
- rem echo %%a
- %%a
- )
- if exist !__yiwuyun.txt! del !__yiwuyun.txt!
- exit /b 0
- :GetTokenTextNAndCount
- setlocal
- set "string=%~1"
- set "___secondParameter=%~2"
- call :GetTokenPlaceNAndCount "^!string^!" "^!___secondParameter^!"
- set /a ___next=0
- set /a tokenTextCount=!tokenCount!+1
- set /a ___n=0
- :startGetTokenTextNAndCount
- set /a ___beforePlace=!tokenPlace%___next%!
- set /a ___first=!___beforePlace!+1
- set /a ___next=!___next!+1
- set /a ___afterPlace=!tokenPlace%___next%!
- set /a ___second=!___afterPlace!-!___beforePlace!-1
- set /a ___n=!___n!+1
- if "!string!"=="" (
- set "tokenText!___n!="
- ) else (
- set tokenText!___n!=!string:~%___first%,%___second%!
- )
- if !___n! lss !tokenTextCount! goto startGetTokenTextNAndCount
- type nul>!__yiwuyun.txt!
- for /l %%a in (1,1,!tokenTextCount!) do (
- echo set "tokenText%%a=!tokenText%%a!">>!__yiwuyun.txt!
- )
- echo set /a tokenTextCount=!tokenTextCount!>>!__yiwuyun.txt!
- endlocal
- for /f "tokens=1 delims=" %%a in ('type %__yiwuyun.txt%') do (
- rem echo %%a
- %%a
- )
- if exist %__yiwuyun.txt% del %__yiwuyun.txt%
- exit /b 0
欢迎光临 批处理之家 (http://www.bathome.net/) | Powered by Discuz! 7.2 |