Line offset of an item (and other similar functions).

Geoff Canyon gcanyon at inspiredlogic.com
Tue Jan 25 11:28:19 EST 2005


On Jan 25, 2005, at 4:32 AM, Alex Tweedly wrote:

> Nope, spoke too soon. That looks convincing, and worked on my initial 
> testing - but doesn't actually work properly in all cases.
>
> The problem is that the CRs are included within items - so given data 
> like
> a,abc,1
> b,def,2
> c,qwe,3
> etc.,  item 1 is "a", item 2 is "abc", item 3 is "1
> b" (i.e. including the cr), item 4 is "def", etc.
>
> Clearly, that means itemOffset will never match what I think of as 
> items that are first (or last) on each line.
>
> In the above case, I want to be able to search for the line containing 
> item "b" and find the second line.

How about:

function lineOffsetOfItem pItem,pData
   replace cr with comma & cr & comma in pData
   return lineOffset((comma & pItem & comma),(comma & pData & comma))
end lineOffsetOfItem

You could make the pData argument by reference if you're dealing with 
large datasets and don't want the overhead of call by value. Then you'd 
have store the offset to return and add a line to put pData back the 
way it was:

replace comma & cr & comma with cr in pData

regards,

Geoff Canyon
gcanyon at inspiredlogic.com



More information about the use-livecode mailing list