In a batch file, how can I get the last token in a variable regardless of whether it is a number or a word and regardless of how many tokens/words there are in the variable.
Some code golf on Eli's answer.
@echo off
set var1=This is a String
REM token_string will be manipulated each loop
set token_string=%var1%
:find_last_loop
for /F "tokens=1*" %%A in ( "%token_string%" ) do (
set last=%%A
set token_string=%%B
goto find_last_loop)
echo %last%
pause
And to find something with ':' delimiters...
for /F "tokens=1* delims=:" %%A in ( "%token_string%" ) do (