4

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
)

1 Answer 1

3

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 
)
Sign up to request clarification or add additional context in comments.

3 Comments

Ok thanks It Works. And one more query. I was trying to goto :itworks when i found new character, instead of echo. But it throws me syntax error. Could u pls help. Thanks Alot. Actually i was pretty new in Batch
@can you show your code ? I cannot be sure where the error comes from
hi npocmaka, i managed somehow. But this Batch script is rolling my head. I have some other queries. stackoverflow.com/questions/36744084/…. Could u pls have a look on this link. Thanks Alot !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.