Line offset of an item (and other similar functions).
Alex Tweedly
alex at tweedly.net
Tue Jan 25 07:32:05 EST 2005
Alex Tweedly wrote:
> J. Landman Gay wrote:
>
>>
>> Like this:
>>
>> get the number of lines in item 1 to itemoffset(tString,tData) of tData
>>
> Thank You !
> I seem to have a mental block against item expressions that cross line
> boundaries. My over-structured brain *knows* that items are small
> things that fit within lines; this is the 3rd or 4th time I've missed
> something because of that blinkered view.
>
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.
Currently I'm using
> function findItemAsLineNumber pItem, pData
> local i, L
> set wholeMatches to true
> -- set the itemDel to TAB
> put 0 into i
> repeat for each line L in pData
> add 1 to i
> if itemOffset(pItem, L) > 0 then return i
> end repeat
> return 0
> end findItemAsLineNumber
but I still think there should be an easier (or at least faster,
shorter, better) way.
-- Alex.
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.3 - Release Date: 24/01/2005
More information about the use-livecode
mailing list