word with in string by Phaelax16th Jan 2004 11:18
|
---|
Summary Function returns true if the specified word is contained within the given string. Description Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com string$ = "The dog jumped over the cat" repeat cls set cursor 0,0 print instr$(string$, "dog") until spacekey() REM Returns true if the specified substring REM is contained within the given string. function instr$(string$, sub$) L1 = len(string$) L2 = len(sub$) for x = 0 to L1-L2 if sub$ = subString(string$,x, x+L2) then exitfunction 1 next x endfunction 0 REM Returns a chunk of a whole string REM starp - is the starting position of the substring that REM you want to be returned. The character at that REM position is not included in the returned result. REM endp - is the position of the last character in the string REM you want to be returned. function subString(s$ as string, startp as integer, endp as integer) l = len(s$) s$ = right$(s$,l-startp) s$ = left$(s$, endp-startp) endfunction s$ |