检查一个带有2个带有批处理Windows的变量的子字符串?
我正在遵循检查字符串的答案对于批处理文件(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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论