批处理去除空格

去掉左侧空格1:
  1. @echo off
  2. set "str=   ab c&>!   " 
  3. for /f "tokens=*" %%i in ("%str%") do echo "☆%%i☆"
  4. pause
复制代码
  去掉左侧空格2:
  1. @echo off
  2. set "str=   ab c&>!   " 
  3. :intercept
  4. if "%str:~0,1%"==" " set "str=%str:~1%"&goto intercept
  5. echo "☆%str%☆"
  6. pause
复制代码
  去掉右侧空格1:
  1. @echo off
  2. set "str=   ab c&>!   " 
  3. for /f "delims=" %%i in ("%str%") do echo "☆%%~nxi☆"
  4. pause
复制代码
  去掉右侧空格2:
  1. @echo off
  2. set "str=   ab c&>!   " 
  3. :intercept
  4. if "%str:~-1%"==" " set "str=%str:~0,-1%"&goto intercept
  5. echo "☆%str%☆"
  6. pause
复制代码
  去掉首尾空格1:
  1. @echo off
  2. set "str=   ab c&>!   " 
  3. for /f "tokens=*" %%i in ("%str%") do echo "☆%%~nxi☆"
  4. pause
复制代码
  去掉首尾空格2:
  1. @echo off
  2. set "str=   ab c&>!   " 

  3. :intercept_left
  4. if "%str:~0,1%"==" " set "str=%str:~1%"&goto intercept_left

  5. :intercept_right
  6. if "%str:~-1%"==" " set "str=%str:~0,-1%"&goto intercept_right
  7. echo "☆%str%☆"
  8. pause
  去掉所有空格:
  1. @echo off
  2. set "str=   ab c&>!   " 
  3. set "str=%str: =%"------注释:冒号后面的空格替换
  4. echo "☆%str%☆"
  5. pause
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页