Posted: 4th Jul 2003 0:46
This snippet finds and highlights a word in a sectence, to find the next same word, type in the same word you previosly searched.

+ Code Snippet
rem +------------------------------+
rem | Word search function example |
rem |------------------------------|
rem | Author : Koshi               |
rem | Date   : July 3 2003         |
rem +------------------------------+

rem Sentence to search in
sent$="The cow jumped over the moon, the little dog laughed to see such sport."
rem The first word to search
word$="the moo"
sync on

rem Main loop
do
cls
ink rgb(200,200,200),0
text 0,0,sent$
print

rem Use the word search function to find the word start
length=word(sent$,word$)
rem Check to see if the word that was searched for was found
if length=0
   print "word not found, search is case sensative."
else
   rem write colored text over the found text
   s=text width(left$(sent$,length))-text width(word$)
   e=text width(left$(sent$,length))
   b=text height(word$)
   ink rgb(200,000,000),0
   text s,0,word$
   ink rgb(200,200,200),0
endif

input "search: ";word$
sync : loop

rem word search function tells the locaction of the found word
function word(sent$,word$)
   p=0 : done=0 : place=0
   rem If the oldword is the same as the current word then search from where it left off last time
   if word$=old_word$ then p=old_p
   rem copare the letters in the word wih the letters in the sentence
   for start=1 to len(word$)
      repeat
         p=p+1
         if mid$(sent$,p)=mid$(word$,start)
            done=done+1
         else
            if done>0 then p=p-done : done=0 : start=1
         endif
      until done>0 or p=>len(sent$)
      rem if the words found the locaction of the place it was found in is stored into 'place'
      if done=len(word$) then place=p
   next start
   old_word$=word$ : old_p=p
endfunction place