Great Tip from Ken Ray about lineOffset

Brian Yennie briany at qldlearning.com
Fri Mar 25 05:26:34 EST 2005


> put lineOffset(cr & "C",cr & tList)
>
> The first cr makes sure the line you're looking for starts with 'C' 
> and the second one is used to 'sync' up the number you're returning.

Definitely a keeper! There are some variations, too, that are worth 
keeping handy:

## find something at the end of a line
put lineOffset("C"&cr, tList&cr)

## find a line which matches on the first item
put lineOffset(cr&"C"&comma, cr&tList)

## find a line which matches on the last item
put lineOffset(comma&"C"&cr, tList&cr)

If you need a general purpose way to find an item's line, you can still 
use this:
put (the number of lines in char 1 to offset("C", tList) of tList)

But note that any time you can use one of the above, they will be 
slightly faster (and have more specific meanings).

Also keep in mind that you can extend this to using the current item or 
line delimiters.

Here's another interesting one to mull over what it does, just for fun:

replace (the lineDelimiter) with (the itemDelimiter) in tList
put (itemOffset(tItem, tList) div itemsPerLine) into tLineNumber
if (tLineNumber > 0) then add 1 to tLineNumber

To ponder: why would this be useful for searching data with a fixed 
number of items per line many times?

- Brian







More information about the use-livecode mailing list