batch remove trailing spaces code example
Example 1: trimspace in bact file
@echo off
set str = This string has a lot of spaces
echo %str%
set str=%str:=%
echo %str%
Example 2: trim all space in bact file
@echo off
setlocal EnableDelayedExpansion
set S= This is a test
echo %S%.
for /f "tokens=* delims= " %%a in ('echo %S%') do (set b=%%a & set b=!b: =_! & echo !b!)
endlocal & goto :EOF