我如何检查是否变量包含Windows批处理文件中的另一个变量? [英] How can I check if a variable contains another variable within a windows batch file?

查看:235
本文介绍了我如何检查是否变量包含Windows批处理文件中的另一个变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设下面的批处理文件

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

I want the output to be a YES followed by a 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

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

I got the basic idea from the following answer but it wasn't searching by a variable so it wasn't completely what I was looking for.

批处理文件:如果找到的子字符串(而不是在一个文件中)

这篇关于我如何检查是否变量包含Windows批处理文件中的另一个变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆