In tip 537, we learned how to perform Environment Variable string substitiution.

To strip spaces from an environment variable, you can use the FOR command:

for /f %i in ("%Variable%") do set Variable=%i

If you want to include this in a batch job, them:

for /f %%i in ("%Variable%") do set Variable=%%i