3958Views2Replies

Author Options:

Batch: How do you search for a variable(text) within another variable(text)? Answered

I want to use a batch file that based on user input, searches for a variable (already set) within the user input.
eg. I figured that this would work:
@echo off
set var=A
set /p var2=Choice: 
(USER TYPES "A B C")
findstr /i /c:"%var%" %var2% OR findstr /i /c:"%var%" ^
if %errorlevel% equ 0 echo.%var% is in %var2%
pause >nul
Exit

2 Replies

user
Prof. PickleBest Answer (author)2013-03-18

You could use something like


@echo off
set var=A
set /p var2=Choice:
echo %var2%|findstr /i "%var%" > file.DOT
if exist file.DOT (echo True) else echo False
pause>nul

Select as Best AnswerUndo Best Answer

user
HoeraufPrograms (author)2013-03-19

Thank you sir, I realized that I already did this in an subnet mask find using ipconfig, but thanks anyway. This actually helped, but you forgot that instead of: if exist file.DOT (echo True) else echo False, you should have written: if %errorlevel% equ 0 then echo.True and if %errorlevel% equ 1 echo.False

Select as Best AnswerUndo Best Answer