bat文件去掉变量字符串前、中、后的空格

简单实现,你一看就懂,直接上代码:

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set abc=                          aaabbbccc

:delleft
if "%abc:~0,1%"==" " set abc=%abc:~1%&&goto delleft
echo 去掉左边空格:%abc%

set abc=aaabbbccc                                                  
:delright
if "%abc:~-1%"==" " set abc=%abc:~0,-1%&&goto delright
echo 去掉右边空格:%abc%

set abc=        aaa     bbb       ccc           
set "abc=%abc: =%"
echo 去掉所有空格:%abc%
pause

 

出处:https://blog.51cto.com/lexsaints/5094214

posted on 2022-11-04 16:38  jack_Meng  阅读(1112)  评论(0编辑  收藏  举报

导航