1

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
)
1
  • 1
    Interesting that you know to use delayed expansion on the echo !YourString%OtherString%=! line (that I suspect is supposed to be echo !YourString:%OtherString%=! but you aren't using it in the if statement as !YourString:%OtherString%=! Commented Jun 13, 2022 at 18:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.