Check if variable contains text in BATCH

Variable =% version%

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

How do I use an IF statement to check if the% version% contains the word " update "?

Thank you for the advanced!

+3


source to share


1 answer


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

+3


source







All Articles