Accessing the last item in a line

J. Landman Gay jacque at hyperactivesw.com
Mon Aug 22 11:20:46 EDT 2011


On 8/22/11 1:12 AM, Pete wrote:
> Thanks Jim and Mark.  I think maybe I used the wrong word when I said
> "expected" since that's kind of in the eye of the beholder!  This beholder
> finds it entirely unexpected.  It means that a string of "a,b," is the same
> as a string of "a,b" as far as number of items is concerned and that doesn't
> seem right to me.  There are clearly three items in the first example, no
> matter if the last one is empty or not.  But it seems that's the way it is
> so I accept it as a quirk.
>
> Here's the problem.  I don't know in advance if the last item is empty or
> not.  I have to admit, I haven't tried either solution but it feels like
> both of them require knowing in advance if the last item is empty.  I think
> perhaps I would be better off using an array instead of a string to deal
> with this.  Pretty sure that would result in 3 keys with empty in the last
> one in the example case.

It's come up many times before. The delimiter belongs to the item before 
it. That's true of both items and lines. How many lines are in each of 
these examples:

This is line one. <cr>
This is line two.


This is line one.<cr>
This is line two.<cr>

I think most would agree that the second example still has only two 
lines, regardless of the trailing return character. If you ask for line 
3 in either example, you will get empty. For your project, asking for 
item 3 will also return empty, so that's how you know.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com




More information about the use-livecode mailing list