How to extract second word of the string via windows batch
I would like to request an assist for this case. I want to get the second word of title so that I could set it as target file.
set title=THE PROGRAM TITLE HERE
set title=one two three four five
for /f "tokens=2" %%i in ("%title%") do set word2=%%i
echo %word2%
This basically grabs the second token (word) from the string. Change the number behind tokens=
into another to get another word. You can also use tokens=2,4
to get the 2nd and 4th word. Additional tokens can be retrieved from %%j
, %%k
etc.
See for /?
for more info.