Supposing you have a string value in a variable STRING
, how can you remove leading and trailing whitespaces with a single command (line)?
For instance, the
Concerning leading whitespaces only, the following code works (_ means TAB):
set "STRING= two spaces, trimmed text string, space-tab-space _ "
rem no "delims=" option given, so defaulting to spaces and tabs:
for /F "tokens=* eol= " %%S in ("%STRING%") do set "LEFTTRIMMED=%%S"
echo "%LEFTTRIMMED%"
However, the trailing whitespaces are still present; but they can removed by the approaches shown in this thread.