is among the words AND find words

Jim Hurley jhurley0305 at sbcglobal.net
Thu Dec 22 02:03:48 EST 2011


Thanks to all for their help with this. I learned a new key word in "token".

So far the function below handles everything reasonable I have thrown at it, including finding "time" in the less than reasonable  text in field 1: 

   "Now is timely the timeless time.-for, all good."

on mouseUp
   put field 1 into tText
   put theWordIsAmongTheWords("time", tText) into msg box --returns true
end mouseUp

function theWordIsAmongTheWords tWord, tList
   --The quote and period are irrelevant to the test for the word, so delete them.
   replace quote with "" in tList
   replace "." with "" in tList
   put empty into tNums

   --Collect all the strings that wordOffset would find.
   repeat
      put wordOffset(tWord,tList, last item of tNums) into tNum
      if tNum = 0 then exit repeat
      put the last item of tNums + tNum & comma after tNums
   end repeat

   --Test each of these strings aginst the word being tested.
   --With the quotes and periods gone, the tokens of sting found work well.
   repeat for each item tWordNum in tNums
      put word tWordNum of tList into tTestWord
      if tWord is among the tokens of tTestWord then return true
   end repeat

   --If all the tests fail, then return false
   return false
end theWordIsAmongTheWords

 








More information about the use-livecode mailing list