ell
ell

Reputation: 81

Check if variable contains a piece of text in BATCH

Variable = %version%

This variable contains this = 5.13-update_01-01-2014

How can use the IF statement to check if the variable %version% contains the word 'update' ??

Thank you in advanced!

Upvotes: 6

Views: 18989

Answers (1)

gbabu
gbabu

Reputation: 1108

A simple demo using conditional statements.

Look at this post (dbenham's answer) for a similar question How to conditionally take action if FINDSTR fails to find a string

C:\>set variable=5.13_01-01-2014

C:\>(echo %variable% | findstr /i /c:"update" >nul) && (echo Variable contains the string "update") || (echo Variable does not have the string "update")
Variable does not have the string "update"

C:\>set variable=5.13-update_01-01-2014

C:\>(echo %variable% | findstr /i /c:"update" >nul) && (echo Variable contains the string "update") || (echo Variable does not have the string "update")
Variable contains the string "update"

Cheers,G

Upvotes: 6

Related Questions