本帖最后由 aloha20200628 于 2024-7-23 11:19 编辑
若批处字符串里包含转义字符,有如一旦撞上 “台风” 就是 “天灾”,只能尽量减免吧...
更新35楼代码如下,用递归子过程替换 for %%s in (%%a) do ... 以便纠正 ,;= 等其余系统默认分隔符以及*?通配符的影响...
- @echo off &setlocal &set "maxZ=0"
- for /f "delims=" %%a in (1.txt) do for /f "delims= " %%b in ("%%a") do (
- set "a=%%a"&call :getMaxZ
- call set/p=%%maxZ%%<nul>0.0
- set/p maxZ=<0.0
- )
- for /f "delims=" %%a in (1.txt) do for /f "delims= " %%b in ("%%a") do (set "a=%%a"&set "ss="&call :printAll)
- del/q "0.0" 2>nul&endlocal &pause &exit/b
- :getMaxZ
- for /f "tokens=1* delims= " %%1 in ("%a%") do (set "a=%%2"&set/p="%%1"<nul>"0.0")
- if "%a%"=="" (exit/b) else for %%v in (0.0) do (set "v=%%~zv")
- (if %v% gtr %maxZ% set "maxZ=%v%") & goto :getMaxZ
- :printAll
- for /f "tokens=1* delims= " %%1 in ("%a%") do (set "s=%%1"&set "a=%%2"&set/p="%%1"<nul>"0.0")
- for %%v in (0.0) do (set/a "z=maxZ-%%~zv")
- setlocal enabledelayedexpansion &set "_s=" &for /l %%k in (1,1,!z!) do (set "_s=!_s! ")
- set "ss=!ss! !s!!_s!" &if "%a%"=="" (set/p="!ss:~1!"<nul&echo,&endlocal&exit/b)
- endlocal &set "ss=%ss%" &goto :printAll
复制代码
|