Accessing the last item in a line

Mark Schonewille m.schonewille at economy-x-talk.com
Mon Aug 22 03:51:59 EDT 2011


Hi Pete,

You can use this method regardless of whether the last item is actually empty, provided that you want to include the last item even if it's empty. If you add an itemdelimiter, you change the number of items though. By adding a char the moment you count the items, you always get the correct number of items.

--
Kind regards,

Mark Schonewille
Economy-x-Talk
Http://economy-x-talk.com

Share the clipboard of your computer over a local network with Clipboard Link http://clipboardlink.economy-x-talk.com


Op 22 aug. 2011 om 08:12 heeft Pete <pete at mollysrevenge.com> het volgende geschreven:

> 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.
> 
> Thanks for the enlightenment though!
> 
> 
> Pete
> Molly's Revenge <http://www.mollysrevenge.com>
> 
> 
> 
> 
> On Sun, Aug 21, 2011 at 9:10 PM, Jim Ault <jimaultwins at yahoo.com> wrote:
> 
>> Yes, this is expected behavior.
>> If the last item or line delimiter is the delimiter char, then there is no
>> 'last item as empty'
>> 
>> You could do a simple modification
>>   put the last item of (myItemList & the itemDel) into theLogicalLastItem
>> 
>> Jim Ault
>> Las Vegas
>> 
>> --- On Sun, 8/21/11, Pete <pete at mollysrevenge.com> wrote:
>> 
>> From: Pete <pete at mollysrevenge.com>
>> Subject: Accessing the last item in a line
>> To: "How to use LiveCode" <use-livecode at lists.runrev.com>
>> Date: Sunday, August 21, 2011, 2:50 PM
>> 
>> It seems that if the last item in a string is empty, then trying to access
>> it by using "item -1" returns the penultimate item, not the last one.  For
>> example, given the string "a,b,"  item -1 of that string comes back as "b".
>> This is on LC 4.6.2, OS X 10.6.8.  Is this expected behavior?
>> 
>> Pete
>> Molly's Revenge <http://www.mollysrevenge.com>
>> _______________________________________________
>> 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
>> _______________________________________________
>> 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
>> 
>> 
> _______________________________________________
> 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