Batch Script - Remove All Spaces


Advertisements

This is used to remove all spaces in a string via substitution.

Example

@echo off 
set str = This string    has    a  lot  of spaces 
echo %str% 

set str=%str:=% 
echo %str%

The key thing to note about the above program is, the : = operator is used to remove all spaces from a string.

Output

The above command produces the following output.

This string    has    a  lot  of spaces
Thisstringhasalotofspaces
batch_script_strings.htm
Advertisements