is among the words AND find words

Jim Hurley jhurley0305 at sbcglobal.net
Wed Dec 21 13:40:44 EST 2011


Bob et. al.



> 
> Message: 14
> Date: Wed, 21 Dec 2011 08:24:59 -0800
> From: Bob Sneidar <bobs at twft.com>
> To: How to use LiveCode <use-livecode at lists.runrev.com>
> Subject: Re: is among the words AND find words
> Message-ID: <BA41A52B-8B6E-4DC0-9996-1253098EAB57 at twft.com>
> Content-Type: text/plain; charset=us-ascii
> 
> I think this underscores the need for the words keyword to be upgraded to reflect real text. For instance, word delimiters could be a property containing all the characters which might be word delimiters, all the punctuations for example. I don't know how you would treat a hyphen. 

That would work.

> 
> Upon thinking about it, I am not sure what the application would be for finding specific words in an english (or any other languages) phrase. It is useful for finding keywords in a Livecode statement for sure. 

> Bob

The application would be one of gatering all the lines in a text field that contain a word or words and displaying them in a second field. The text might also include quotes and that messes up the wordOffset function. 

Turns out the tokens don't work since the period is not a token so the token 1 of  "time." is time.

Astonishingly, it turns out that LC all allows for 

    Put "time" is among the tokens of "Now is the time, for all good men."

That returns true.

But

     Put "men" is among the tokens of "Now is the time, for all good men."

returns false--because of the period after "men"

I think I'll just strip the lead and trailing characters from the resulting wordOffset word, using something like:

function stripEnds tWord
   repeat 
      if charIsNotLetter (char 1 of tWord) then
         delete char 1 of tWord
         next repeat
      else
         exit repeat
      end if
   end repeat
   repeat
      if charIsNotLetter (char -1 of tWord) then
         delete char -1 of tWord
         next repeat
      else
         exit repeat
      end if
   end repeat
   return tWord
end stripEnds

function charIsNotLetter tChar
   put charToNum(tChar) into tNum
   switch
      case tNum >= charToNum("a") and tNum <= charToNum("z") 
         return false
         break
      case tNum >= charToNum("A") and tNum <= charToNum("Z") 
         return false
         break
      default
         return true
   end switch
end charIsNotLetter 

But I would prefer RR to implement your suggestion of augmenting  the delimiters for "word" to include all non-letters.



More information about the Use-livecode mailing list