4

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
1
  • How to extract LAST word of the string?
    – Andrey
    May 1, 2019 at 9:09

2 Answers 2

5
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.

0

You could call a local subroutine, passing the title unquoted. In the subroutine, that would give you a list of parameters, e.g., %1 for "THE", %2 for "PROGRAM".

Something like

call :second
echo The second word is %second_word%

and later:

:second
   set second_word=%2
   goto :eof

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .