我如何检查variables是否包含Windowsbatch file中的另一个variables?

假设下面的batch file

set variable1=this is variable1 set variable2=is set variable3=test if variable1 contains variable2 ( echo YES ) else ( echo NO ) if variable1 contains variable3 ( echo YES ) else ( echo NO ) 

我希望输出是一个YES,然后是NO

我已经解决了这个问题

 setLocal EnableDelayedExpansion set variable1=this is variable1 set variable2=is set variable3=test if not "x!variable1:%variable2%=!"=="x%variable1%" ( echo YES ) else ( echo NO ) if not "x!variable1:%variable3%=!"=="x%variable1%" ( echo YES ) else ( echo NO ) endlocal 

我从下面的答案得到了基本的想法,但它不是由一个变量搜索,所以它不完全是我所期待的。

批处理文件:查找子字符串是否在字符串中(不在文件中)

其他方式:

 echo %variable1%|find "%variable2%" >nul if %errorlevel% == 0 (echo yes) else (echo no) 

加里·布伦顿的回答对我不起作用。

如果你尝试使用set variable1="C:\Users\My Name\" ,那么最终会出现一个错误:

  'Name\""' is not recognized as an internal or external command 

调整这个答案找出一个环境变量是否包含一个子字符串 ,我结束了:

 echo.%variable1%|findstr /C:"%variable2%" >nul 2>&1 if not errorlevel 1 ( echo Found ) else ( echo Not found )