Click here for important information about

Solved batch: find substr in string

Hewlett-packard / Pavilion touchsmart amd a...
January 14, 2014 at 06:47:17
Specs: Windows 7, 8GB
I made an A.I. using notepad, and it speaks, but im concerned because it already has over 7000 lines of code and it takes about 1 second to respond to something at the end of the code, which isnt bad, but he knows about 0.5% of the critcal information he needs to pass any test at a grade 5 level so im concerned that i may need to rearrange and shorten the code, heres what i need, i need a code in batch that searches my variable, named input, for a certain sentance, which may or may not be the full value of the variable, for example: if my input was equal to "i am going swimming" and i wanted it to see if the variable contained "i am going" and if it did it would open another batch file named "goingto.bat"

See More: batch: find substr in string

January 17, 2014 at 13:30:15
I don't see what the first lines have to do with the latter lines, and I don't understand how "I am going" relates to "goingto".

Hi there.

Report •

January 20, 2014 at 23:19:18
✔ Best Answer
Nothing to do with notepad.

To find a substring:

::====== script starts here ===============
:: chk for substr in var * "i am going" in "i am going swimming"
:: swim.bat 2014-01-15 17:37:30.95
@echo off & setLocal enableDELAYedeXpansioN

:: V is the var
:: S is the str to find in V
:: T is a chunk of S [and then V]
:: D is the difference in length
:: O is offset

set V=i am going swimming
set S=am going

call :sub1
call :sub2
set/a D=!len-V!-!len-S!

call :main !len-S!
goto :eof
set O=
for /L %%a in (0 1 !D!) do (
set T=!V:~%%a,%1!
if "!T!" equ "!S!" set O=%%a && goto :done-main
if defined O (
echo.!S! found at offset !O!
) else (
echo not found
goto :eof

for /L %%i in (1 1 30) do (
set T=!V:~%%i,1!
if '!T!' equ '' set len-V=%%i && goto :done-sub1
goto :eof

for /L %%i in (1 1 30) do (
set T=!S:~%%i,1!
if '!T!' equ '' set len-S=%%i && goto :done-sub2
goto :eof
::====== script ends here =================

M2 Golden-Triangle

Report •
Related Solutions

Ask Question