is among the words AND find words
jhurley0305 at sbcglobal.net
Thu Dec 22 01:36:47 CST 2011
Strike most of my last message. It appears that most of the function can be replaced with an examination of the entire text (dah) as in:
put tWord is among the tokens of tList into tTest
This tests the whole text; it is not necessary to test each string containing the word individually.
But remove the quotes and periods first.
> 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.
> 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