Skip navigation

JSI Tip 0708. How do I strip spaces from an environment variable?

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

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.