Remove All Spaces from Variable in Batch File

email me

This makes logic testing much easier

For /f “tokens=1,2 delims==” %%a in (‘findstr “Citrix Receiver Updater 4.2.0” guid.txt’) DO (
SET MyVar=%%b
SET MyVar=!MyVar: =!
ECHO !MyVar!
)

 

Others

Remove quotes:
SET Line=”C:\Program Files\”
SET Line=%Line:”=%
echo %Line% — will output: C:\Program Files\

Remove a trailing backslash:
SET Line=C:\Windows\
IF “%Line:~-1%”==”\” SET Line=%Line:~0,-1%
echo %Line% — will output: C:\Windows