How to extract version number in a Windows batch file?

后端 未结 3 1905
小鲜肉
小鲜肉 2021-01-07 00:23

I need to extract the Major , Minor and Revision numbers from a string and to achieve this I\'m trying to split a string in a batch file using a \'.\' character as the delim

3条回答
  •  再見小時候
    2021-01-07 00:44

    Here you go...

    @ECHO OFF & SETLOCAL 
    set /p "ReleaseVersion=Please specify the software release version : "
    
    for /F "tokens=1,2,3 delims=." %%a in ("%ReleaseVersion%") do (
       set Major=%%a
       set Minor=%%b
       set Revision=%%c
    )
    
    echo Major: %Major%, Minor: %Minor%, Revision: %Revision%
    

    Input/output:

    Please specify the software release version : 1.0.2

    Major: 1, Minor: 0, Revision: 2

提交回复
热议问题