:trimSpaces2 retval string -- trims spaces around string and assigns result to variable :: -- retvar [out] variable name to store the result in :: -- string [in] string to trim, must not be in quotes for /f "tokens=1*" %%A in ("%*") do set "%%A=%%B" EXIT /b