Bat removes spaces in variable strings

Bat removes spaces in variable strings

foreword

bat has made a time punching tool, but when the time is in single digits, there will be spaces in what bat gets.

source code

In this way, writing to the file will not bother you because the file name does not allow spaces.

@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

transferred from

The original
bat file removes the spaces in the variable string

Guess you like

Origin blog.csdn.net/a71468293a/article/details/127747191