trimspace in bact file

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

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

Also in C++: