ibingshan

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

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-02-17
  • 2022-01-07
猜你喜欢
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2021-11-21
  • 2022-01-08
  • 2022-01-17
  • 2021-09-17
相关资源
相似解决方案