小编Oop*_*Oop的帖子

如何在批处理文件中删除用户提供的输入的尾随和前导空格?

我知道如何在预定义变量时执行此操作.但是,当要求用户输入某种输入时,如何修剪前导和尾随空格?这是我到目前为止:

@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)

whitespace input trim batch-file

32
推荐指数
5
解决办法
12万
查看次数

标签 统计

batch-file ×1

input ×1

trim ×1

whitespace ×1