Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

https://stackoverflow.com/questions/34077831/how-to-see-if-a-string-contains-a-substring-using-batch

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/find

@ECHO OFF
SET Str=Hello

::SET SubStr=el
SET SubStr=EL
::SET SubStr=eZ

CALL :SUBSTRINGCHECK %Str% %SubStr% RESULT
ECHO %RESULT%
PAUSE

:SUBSTRINGCHECK
SET RESULT=FALSE
SET Str=%~1
SET SubStr=%~2
CALL :reset_error
ECHO "%Str%" | FIND /i "%SubStr%" >nul
IF %ERRORLEVEL% EQU 0 (
 Set RESULT=TRUE
)
SET %3=%RESULT%
exit /b

:reset_error
exit /b 0
  • No labels