Extracting minor version number from C# source using MSDOS batch file

0

I need to extract the version number from this C# source line using MSDOS batch file:

public const int major_version = 2;

My attempt:

::  Extract the number-token from the major version string.
::  The number-token has a semicolon appended.
for /F "tokens=6" %%a in ( str_Major_REV) do set number_token=%%a

This results in the variable number_token as 2;.

How can I remove the ';'?
{The ';' is used as a line separator by the delims parameter.}

Background:
The batch file is run by Jenkins build server. I want the batch file to:

  1. Extract the number.
  2. Increment the number and save as environment / batch file variable.
  3. Replace the original number with the incremented number.
  4. Use the number in a folder name.
  5. Use the number in a Code Management System version/label.

Items 4 and 5 are reasons I need the semicolon removed from the number token.

Environment
Windows server 2008

Thomas Matthews

Posted 2018-05-04T01:21:41.853

Reputation: 259

1(1) delims containing semicolon works fine for me on Vista, which should be the same as 2008, and is not a 'line separator' (2) To remove the last character %number_token:~0,-1% (3) To remove semicolon anywhere %number_token:;=% – dave_thompson_085 – 2018-05-04T05:01:27.357

A much easier way is a for loop for %%A in (%str_Major_Rev%) do @set "number_token=%%A" Space, semocolon, comma, tab are all argument seperators. The loop wil set all items, but the last will stay. – LotPings – 2018-05-04T08:37:41.073

No answers