转一下以前写的代码:
去掉左侧空格1:- @echo off
- set "str= ab c&>! "
- for /f "tokens=*" %%i in ("%str%") do echo "☆%%i☆"
- pause
复制代码 去掉左侧空格2:- @echo off
- set "str= ab c&>! "
- :intercept
- if "%str:~0,1%"==" " set "str=%str:~1%"&goto intercept
- echo "☆%str%☆"
- pause
复制代码 去掉右侧空格1:- @echo off
- set "str= ab c&>! "
- for /f "delims=" %%i in ("%str%") do echo "☆%%~nxi☆"
- pause
复制代码 去掉右侧空格2:- @echo off
- set "str= ab c&>! "
- :intercept
- if "%str:~-1%"==" " set "str=%str:~0,-1%"&goto intercept
- echo "☆%str%☆"
- pause
复制代码 去掉首尾空格1:- @echo off
- set "str= ab c&>! "
- for /f "tokens=*" %%i in ("%str%") do echo "☆%%~nxi☆"
- pause
复制代码 去掉首尾空格2:- @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
复制代码 以上代码能兼容除双引号外的其他特殊字符。 |