Master James
Master James

Reputation: 338

What does %var:~0,4% and %var:.=% mean in batch file?

Here is my sample batch file code and I really don't know what it does.

set TEMPRPSW=%RPSW_VERSION%
set RELVER=%TEMPRPSW:~0,4%
set RELVER=%RELVER:.=%
if %RELVER% GEQ 30 goto :eof

Please give me a working sample.

Upvotes: 2

Views: 11536

Answers (1)

devtech
devtech

Reputation: 364

That takes a 4 character long substring of TEMPRPSW, starting from character 0. Meaning, it takes the first 4 characters of TEMPRPSW and puts them in RELVER.

set TEMPRPSW=abcdef
set RELVER=%TEMPRPSW:~0,4%
echo %RELVER%       -> will print abcd

%VAR:str=% removes str

set RELVER=123.456
set RELVER=%RELVER:.=%
echo %RELVER%       -> will print 123456 with no .

here is a nice article: https://www.dostips.com/DtTipsStringManipulation.php

Upvotes: 6

Related Questions