- 1 year ago
Remove space from start of variable in cmd
Comment
1 / 1
To remove leading spaces from a variable in a Windows command prompt (CMD), you can use the following syntax:
batchset "VAR=%VAR: =%"
Replace VAR
with the name of your variable.
Here's an example to illustrate how it works:
batch@echo off
set "VAR= Hello World"
echo Before: "%VAR%"
set "VAR=%VAR: =%"
echo After: "%VAR%"
This script sets the VAR
variable with some leading spaces, and then it removes those leading spaces using the set "VAR=%VAR: =%"
command. The output will show the value of the variable before and after removing the leading spaces.
Note that the quotes around the variable assignment (set "VAR=%VAR: =%"
) are important to preserve the spaces in the variable value.