In a batch file, I have a string abcdefg. I want to check if bcd is in the string.
Unfortunately it seems all of the solutions I’m finding search a file for a substring, not a string for a substring.
Is there an easy solution for this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, you can use substitutions and check against the original string:
The
%str1:bcd=%bit will replace abcdinstr1with an empty string, making it different from the original.If the original didn’t contain a
bcdstring in it, the modified version will be identical.Testing with the following script will show it in action:
And the results of various runs:
A couple of notes:
ifstatement is the meat of this solution, everything else is support stuff.xbefore the two sides of the equality is to ensure that the stringbcdworks okay. It also protects against certain “improper” starting characters.