::code by
youxi01@cn-dos.net
@echo off & setlocal enabledelayedexpansion
set "str1=qwer/asdf2/asd34f/13546641/asdf/aaaa"
set "str2=aaaaa2/45321/asdfssasd/asdaa"
call :GetNum "%str1%" num1
call :GetNum "%str2%" num2
call :Split %num1%
REM Mnum保存结果的段数(用来接受最大的段数);
REM 将num的值重新归0,用来继续调用"函数"
REM flag为进位标记,如果为1,则下段数字加1;这里为初始值,设置为1。
set/a Mnum=%num%,num=0,flag=0
call :Split %num2%
if %Mnum% LSS %num% set/a Mnum=%num%
set/a Mnum_=%Mnum%-1
for /l %%i in (1 1 %Mnum_%) do (
set/a Rnum%%i+=!flag!
if !Rnum%%i! GTR 10000 set/a flag=1
REM 在前面加000,是为了补齐数字的,防止333这样位数不足4位的数字。
set Rnum%%i=000!Rnum%%i!
set Rnum%%i=!Rnum%%i:~-4!
set Rstr=!Rnum%%i!!Rstr!)
set/a Rnum%Mnum%+=%flag%
echo !Rnum%Mnum%!!Rstr!
pause>nul
:GetNum OBJ Res
for /f "delims=/ tokens=1,*" %%i in ("%~1") do (
REM 利用是否大于a,来检测是否是数字,如果是,则一定小于a(不管是多少位的数字)
REM 如果检测到数字,则退出。
if %%i LSS a set %2=%%i & goto :eof
REM 循环检测;
call :GetNum "%%j" %2
) & goto :eof
:Split OBJ
set str=%~1
set/a num+=1
REM 如果,切割后的数字小于10000,则设置自身的值为原值加上该数字,并退出;
if %str% LSS 10000 set/a Rnum%num%+=%str% & goto :eof
REM 利用willsort的办法,屏除类似0001给利用set/a计算带来的错误;
set/a Rnum%num%+=10000%str:~-4%%%10000
set str=%str:~0,-4%
call :Split "%str%"
::code by
youxi01@cn-dos.net
@echo off & setlocal enabledelayedexpansion
set "str1=qwer/asdf2/asd34f/13546641/asdf/aaaa"
set "str2=aaaaa2/45321/asdfssasd/asdaa"
call :GetNum "%str1%" num1
call :GetNum "%str2%" num2
call :Split %num1%
REM Mnum saves the number of segments of the result (used to accept the maximum number of segments);
REM Reset the value of num to 0 to continue calling the "function"
REM flag is the carry flag, if it is 1, the next segment number is added by 1; here it is the initial value, set to 1.
set/a Mnum=%num%,num=0,flag=0
call :Split %num2%
if %Mnum% LSS %num% set/a Mnum=%num%
set/a Mnum_=%Mnum%-1
for /l %%i in (1 1 %Mnum_%) do (
set/a Rnum%%i+=!flag!
if !Rnum%%i! GTR 10000 set/a flag=1
REM Adding 000 in front is to fill the number, to prevent numbers with less than 4 digits like 333.
set Rnum%%i=000!Rnum%%i!
set Rnum%%i=!Rnum%%i:~-4!
set Rstr=!Rnum%%i!!Rstr!)
set/a Rnum%Mnum%+=%flag%
echo !Rnum%Mnum%!!Rstr!
pause>nul
:GetNum OBJ Res
for /f "delims=/ tokens=1,*" %%i in ("%~1") do (
REM Use whether it is less than a to detect whether it is a number. If it is, it must be less than a (no matter how many digits it is)
REM If a number is detected, exit.
if %%i LSS a set %2=%%i & goto :eof
REM Loop detection;
call :GetNum "%%j" %2
) & goto :eof
:Split OBJ
set str=%~1
set/a num+=1
REM If the cut number is less than 10000, set its own value to the original value plus the number and exit;
if %str% LSS 10000 set/a Rnum%num%+=%str% & goto :eof
REM Use the willsort method to eliminate errors caused by set/a calculation similar to 0001;
set/a Rnum%num%+=10000%str:~-4%%%10000
set str=%str:~0,-4%
call :Split "%str%"