本帖最后由 aloha20200628 于 2024-7-18 12:08 编辑
回复 1# shenlong - @echo off &setlocal enabledelayedexpansion &set "maxZ=0"
- for /f "delims=" %%a in (1.txt) do for %%s in (%%a) do (
- set "s=%%s" & (call :_strLen s z)
- if !z! gtr !maxZ! set "maxZ=!z!"
- )
- set "ms=" &for /l %%n in (1,1,!maxZ!) do set "ms=!ms! "
- endlocal &set "maxZ=%maxZ%"&set "ms=%ms%"
- setlocal enabledelayedexpansion
- for /f "delims=" %%a in (1.txt) do (
- set "s="
- for %%s in (%%a) do (set "_s=%%s"&set "_s=!_s!%ms%"&set "s=!s! !_s:~0,%maxZ%!")
- echo,!s:~1!
- )
- endlocal&pause&exit/b
- :_strLen
- set "_str=_!%~1!" &set "_Len=0"
- for %%n in (64 32 16 8 4 2 1) do (
- if "!_str:~%%n,1!" neq "" (set/a "_Len+=%%n"&set "_str=!_str:~%%n!")
- )
- set "%~2=!_Len!" &exit/b
复制代码
特此备注》重写了原代码,改用批处 ‘原装’ 的字符串长度计算方法,再请出制表符 ‘显灵’,似乎消除了以前格式化输出时中英文字符混合字段的占位问题...
|