检查批处理文件(Windows)一个子字符串? [英] Check a string for a substring in a batch file (Windows)?

查看:133
本文介绍了检查批处理文件(Windows)一个子字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有一个名为$ 1个变量一些文字。现在,我要检查如果$ 1包含某些字符串。如果包含特定字符串我想打印的消息。印刷是没有问题的,问题是检查...想法如何做到这一点?

Let's say I have some text in a variable called $1. Now I want to check if that $1 contains a certain string. If it contains a certain string I want to print a message. The printing is not the problem, the problem is the check...ideas how to do that?

推荐答案

在我看来,最简单的方法是这样的:

The easiest way in my opinion is this :

set YourString=This is a test

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

Basiclly后字符串':'是你正在寻找的字符串,您使用的是不盈的,如果因为%字符串: *的%将删除* 从字符串使他们不相等的。

Basiclly the string after ':' is the string you are looking for and you are using not infront of the if because %string:*% will remove the * from the string making them not equal.

这篇关于检查批处理文件(Windows)一个子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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