::此程序为批处理中字符串值的顺序转换而编写, 一般作为子程序被其他程序调用, 也可以将此程序稍做修改, 添加入特定批处理程序中作为子模块调用.
@echo off
if [%1]==[$] goto %2
if [%1]==[] goto nullargu
:main 主模块: count, match 句参数列表可以根据需要重新设定和增减
set factor=%1
call %0 $ count 1 2 3 4 5 7 8 9
call %0 $ match c d e f g h i j
goto display
:count 计数模块: 根据指定参数 factor 设置变量值 #a1, #a2
if [%3]==[] goto overflow
set #a1=%#a1%-
if not [%#a1%]==[----------] goto count_2
set #a1=
set #a2=%#a2%+
if [%#a2%]==[++++++++++] goto overflow
:count_2
if [%3]==[%factor%] goto end
shift
goto count
:match 匹配模块: 循环递增变量 #b1, #b2, 若分别与 #a1, #a2 相等, 则指定结果值为当前循环的参数 3.
if [%3]==[] goto overflow
set #b1=%#b1%-
if not [%#b1%]==[----------] goto match_2
set #b1=
set #b2=%#b2%+
if [%#b2%]==[++++++++++] goto overflow
:match_2
if [%#a1%]==[%#b1%] if [%#a2%]==[%#b2%] set result=%3
if not [%result%]==[] goto end
shift
goto match
:display 显示模块: 显示赋值结果
if [%error%]==[] echo %factor% convert %result%
set result=
set factor=
set error=
set #a1=
set #a2=
set #b1=
set #b2=
goto end
:nullargu
echo.
echo Error: argument 1 not specified.
echo.
goto end
verflow
echo.
echo Error: number is overflow.
set error=overflow
echo.
goto end
:end |
|