检查一个带有2个带有批处理Windows的变量的子字符串?

发布于 2025-02-07 00:15:26 字数 833 浏览 0 评论 0原文

我正在遵循检查字符串的答案对于批处理文件(Windows)中的子字符串?Wald的答案

set YourString=This is a test

If NOT "%YourString%"=="%YourString:test=%" (
    echo Yes
) else (
    echo No
)

有点工作。但是,我很难将测试=更改为自己的变量。我跟随另一个串联的答案 2个变量,但它们似乎都没有起作用。 基本上,我想检查' yourstring '包含'其他'没有超长代码。

这是我拥有的代码现在

set YourString=This is a test
set OtherString=test

If NOT "%YourString%"=="%YourString:%%=%" (
    echo Yes
echo !YourString%OtherString%=!
pause
) else (
    echo No
echo "%YourString:test=%"
pause
)

I'm following the answer in Check a string for a substring in a batch file (Windows)?. Wald's answer,

set YourString=This is a test

If NOT "%YourString%"=="%YourString:test=%" (
    echo Yes
) else (
    echo No
)

does kinda work. However, I'm having trouble changing test= into a variable of my own. I followed another answer of concatenating 2 variables but none of them seemed to work. Basically, I want to check if 'YourString' contains 'OtherString' without a super long amount of code.

Here is the code I have right now

set YourString=This is a test
set OtherString=test

If NOT "%YourString%"=="%YourString:%%=%" (
    echo Yes
echo !YourString%OtherString%=!
pause
) else (
    echo No
echo "%YourString:test=%"
pause
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文