title: Last token in batch variable
body: <p>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.</p>
  
  <p>I will be passing an argument into the batch file like this:</p>
  
  <p><code>C:\execbatch.bat "This is example one"</code>
  or
  <code>C:\execbatch.bat "This is example number 2"</code></p>
  
  <p>And then the batch file will be like this:</p>
  
  <pre><code>@echo off
  
  SET var=%1
  SET last=some command to grab the last token of %var%
  echo %last%
  exit
  </code></pre>
  
  <p>Essentially, I need to be able to always grab the last token, in these examples, I would want to grab <code>one</code> from example 1 and <code>2</code> from example 2.</p>
  
  <p><strong>ADDITIONAL INFORMATION:</strong></p>
  
  <p>It is not the command line arguments that are the issue, that was just a simplified example:</p>
  
  <p>The case is that I am calling a command inside of a batch file and sending its output to a variable like so:</p>
  
  <p><code>C:\execbatch.bat memory</code> or <code>C:\execbatch.bat cpu</code></p>
  
  <p>And then in the batch file:</p>
  
  <pre><code>For /F "Tokens=*" %%I in ('c:\monitor.exe -C custom_performance_counter -t %1 -w 80 -c 90') Do Set COMMANDOUTPUT=%%I
  
  Echo %COMMANDOUTPUT%
  Set CURRENTVALUE=some command to grab the last token of %COMMANDOUTPUT%
  Echo "The current value is %CURRENTVALUE%"
  </code></pre>
  
  <p>This will output various results depending on the check type; however in every case the last token/variable is always the current value albeit either number or word.</p>