批处理去除空格
去掉左侧空格1:
复制代码 去掉左侧空格2:
复制代码 去掉右侧空格1:
复制代码 去掉右侧空格2:
复制代码 去掉首尾空格1:
复制代码 去掉首尾空格2:
去掉所有空格:
复制代码 以上代码能兼容除双引号外的其他特殊字符。
- @echo off
- set "str= ab c&>! "
- for /f "tokens=*" %%i in ("%str%") do echo "☆%%i☆"
- pause
- @echo off
- set "str= ab c&>! "
- :intercept
- if "%str:~0,1%"==" " set "str=%str:~1%"&goto intercept
- echo "☆%str%☆"
- pause
- @echo off
- set "str= ab c&>! "
- for /f "delims=" %%i in ("%str%") do echo "☆%%~nxi☆"
- pause
- @echo off
- set "str= ab c&>! "
- :intercept
- if "%str:~-1%"==" " set "str=%str:~0,-1%"&goto intercept
- echo "☆%str%☆"
- pause
- @echo off
- set "str= ab c&>! "
- for /f "tokens=*" %%i in ("%str%") do echo "☆%%~nxi☆"
- pause
- @echo off
- set "str= ab c&>! "
- :intercept_left
- if "%str:~0,1%"==" " set "str=%str:~1%"&goto intercept_left
- :intercept_right
- if "%str:~-1%"==" " set "str=%str:~0,-1%"&goto intercept_right
- echo "☆%str%☆"
- pause
- @echo off
- set "str= ab c&>! "
- set "str=%str: =%"
- echo "☆%str%☆"
- pause