Last token in batch variable

后端 未结 5 2043
死守一世寂寞
死守一世寂寞 2020-12-11 03:54

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.

5条回答
  •  天命终不由人
    2020-12-11 04:08

    Why so complicated?

    Solution for a string in a variable:

    set var1=This is a String
    for %%A in (%var1%) do set last=%%A
    

    echo last=%last%

    Solution for the result of an external command:

    set xcmd=c:\monitor.exe -C custom_performance_counter -t %1 -w 80 -c 90
    for /f "tokens=*" %%I in ('%xcmd%') do for %%A in (%%~I) do set last=%%A
    echo last=%last%
    

提交回复
热议问题