Bat file script to check if a string contains another string
I need to write a batch file that will check if a variable contains a specific value. I tried the following:
If "%%a"=="%%a:%pattern%" (
echo Yes
) else (
echo No
)
example input: %% a = "bob binson"% Lacquered% = "binson"
I never get Yes, printed! can anyone please tell me what i missed or give an example of how he would do this?
Thanks in Advance
+3
source to share
1 answer
Substring operations are not available in for
pluggable parameters. You need to assign data to a variable and then perform an operation on that variable
@echo off setlocal enableextensions disabledelayedexpansion >"tempFile" ( echo bob binson echo ted jones echo binson ) set "pattern=binson" for /f "usebackq delims=" %%a in ("tempFile") do ( echo data: %%a set "line=%%a" setlocal enabledelayedexpansion if "!line:%pattern%=!"=="!line!" ( echo .... pattern not found ) else ( echo .... pattern found ) endlocal ) del /q tempFile
+1
source to share