John
John

Reputation: 109

Windows Batch Script to find a variable contains string or Variable has values

I have a Variable in my Batch %rev%

I need to check whether it contains a string "new" or it has a value of random numbers in it.

Any help Appreciated.

I was trying with the below code but it doesnt work.

if /I "%rev%"=="new" (
echo String has new
) else (
echo it doesnt has new
)

Upvotes: 4

Views: 10057

Answers (1)

npocmaka
npocmaka

Reputation: 57252

you can try with :

if /I "%rev:new=%" neq "%rev%" (
echo String has new
) else (
echo it doesnt has new
)

or with (a little bit slower):

(echo(%rev%)|find /i "new" >nul && (
  echo String has new
)||(
  echo it doesnt has new 
)

Upvotes: 3

Related Questions