我知道如何在预定义变量时执行此操作.但是,当要求用户输入某种输入时,如何修剪前导和尾随空格?这是我到目前为止:
@echo off
set /p input=:
echo. The input is %input% before
::trim left whitespace
for /f "tokens=* delims= " %%a in ("%input%") do set input=%%a
::trim right whitespace (up to 100 spaces at the end)
for /l %%a in (1,1,100) do if "!input:~-1!"==" " set input=!input:~0,-1!
echo. The input is %input% after
pause
Run Code Online (Sandbox Code Playgroud)