There is another way - beside the ones mentioned on that page - to remove leading and trailing spaces:
Code: Select all
set str= 15 Leading and Trailing Spaces to truncate &rem
echo."%str%"
for /f "tokens=*" %%A in ("%str%") do set str=%%~pnxA
set str=%str:~1%
echo."%str%"
Code: Select all
" 15 Leading and Trailing Spaces to truncate "
"15 Leading and Trailing Spaces to truncate"
Reporting path filename and extension will cause a leading "\" (from the path) that has to be stripped before getting the "unspaced" string.
HTH.
(obviously you should't use this method when the string contains a filename ..)