Wednesday, April 18, 2012

Sophisticated way of how to check if the string contains substring in batch

Some time ago I posted the way to check if the certain string contains the substring via batch script. Here is more sophisticated solution.

@ECHO OFF

FOR /F "tokens=1 delims=" %%A IN ('echo %1^|find /C "%2"') DO SET RESULT=%%A

IF %RESULT% NEQ 0 GOTO SUCCESS 

:FAIL
ECHO.Substring was not found.
EXIT /B 1


:SUCCESS
ECHO.Substring was found.

No comments:

Post a Comment