只能去掉末尾100个空格,要是大于100个空格,必须改动for /l中的数字,这也是此代码的不合理之处:- @echo off&setlocal enabledelayedexpansion
- for /f "tokens=*" %%i in (a.txt) do (
- set str=%%i
- call :lp
- )
- pause&exit/b
-
- :lp
- for /l %%a in (-1 -1 -100) do (
- set "str1=!str:~%%a,1!"
- if not "!str1!"==" " (
- set n=%%a&set /a n+=1
- for %%i in (!n!) do set "str1=!str:~0,%%i!"
- echo "!str1!"&goto :eof
- )
- )
复制代码
|