How to extract the numbers after a character in windows batch files -
hi need extract last part of string after last dot example:
1.2.37 ==> need 37 1.2.567 ==> need 567
as can see number of characters after dot not fixed expressions
base=%fullver:~0,-2%
can't used. how can achieve this?
@echo off setlocal enableextensions disabledelayedexpansion set "fullver=1.2.456" %%a in ("%fullver:.=\%") set "base=%%~na" echo %base%
the trick replace dots backslashes, process string path , retrieve name of last element in it.
alternatively, if elements need retrieved, instead of for
, for /f
used tokenize variable using dots separators
@echo off setlocal enableextensions disabledelayedexpansion set "fullver=1.2.456" /f "tokens=1-3 delims=." %%a in ("%fullver%") ( set "major=%%a" set "minor=%%b" set "build=%%c" ) echo [%major%] [%minor%] [%build%]
Comments
Post a Comment