When is a Word not a Word?

Peter Haworth pete at mollysrevenge.com
Mon Jan 10 13:09:04 EST 2011


Thanks Peter.  Unfortunately, I need wholematches to be true for my purposes.  I've got round the problem by first searching without quotes and if nothing is found, searching again with quotes.  I'm actually going back to the built in Find/Replace functions because I've realised there are lots of delimiters in scripts that the word offset functions don't handle - quotes, square brackets, round brackets, comma, etc.

Pete Haworth

On Jan 10, 2011, at 5:49 AM, Peter Brigham MD wrote:

> On Jan 9, 2011, at 5:48 PM, Peter Haworth wrote:
> 
>> Got weird things going on with the wordoffset function.  The code is:
>> 
>> put wordoffset(field "Selection",myLine) into mywordoffset
>> 
>> if field Selection contains xyz and myline contains abc def xyz, then wordoffset returns 3.
>> 
>> if field Selection contains xyz and myline contains abc def "xyz" (xyz in double quotes this time), wordoffset returns zero.
>> 
>> I've tried this with all combinations of casesensitive and wholematches true and false.
>> 
>> According to the dictionary, "A word is delimited by one or more spaces, tabs, or returns, or enclosed by double quotes" so why isn;t "xyz" recognised as a word?
>> 
>> Pete Haworth
> 
> Word 3 of
>   abc def "xyz"
> is
>   "xyz"
> not
>   xyz
> 
> The business about "enclosed in double quotes" refers to the (to my mind) puzzling convention in RC, dating back to the old HC days, of considering anything in double quotes to be one word. So, word 3 of
>   abc def "ghi jklmno"
> is
>   "ghi jklmno"
> (with the quotes included). There was a debate about the merits of this convention a while back -- search the archives.
> 
> But you might have wholematches set to true.
> 
> If you do:
>   put "abc def ghi" && quote & "xyz" & quote into tSentence
>   put "xyz" into tWord
>   put s & cr & wordoffset(tWord, tSentence)
> then you get
>   abc def ghi "xyz"
>   4
> unless the wholematches = true, in which case the wordoffset returns 0.
> 
> -- Peter
> 
> Peter M. Brigham
> pmbrig at gmail.com
> http://home.comcast.net/~pmbrig
> 
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
> 





More information about the use-livecode mailing list