bat 判断变量字符串中是否包含字符串

bat 判断变量字符串中是否包含字符串

@echo off

rem way 1
set str=machine-order-service
set matchStr=orderd
echo %str% | findstr %matchStr% >nul && echo yes || echo no
rem end way 1
pause

rem way 2
setLocal EnableDelayedExpansion
if not "x!str:%matchStr%=!"=="x%str%" (
    echo Y
) else (
    echo N
)
endlocal
rem end way 2

pause

 代码注释:

  在 way 1 中,加了 >nul 就可以不打印 echo 的内容, way1 可以不设置 setlocal

posted @ 2019-05-15 10:23  ibingshan  阅读(18623)  评论(2编辑  收藏  举报