A slightly disturbing problem about items

Jim Ault JimAultWins at yahoo.com
Sat Jun 4 19:19:33 EDT 2005


One further note, as Dennis says, ( and another suggestion/technique )
In the message box....
   put last item of "my,brown,shoes"   -> shoes
   put last item of "my,brown,"   -> brown

   put item 3 of "my,brown,shoes"   -> shoes
   put item 3 of "my,brown,"   -> ""

So testing to see if the last item is empty will not work as you might
think.
You need to test to see if the last char is the delimiter.
This is especially true when you build the string using variables and the
last variable is empty, yet you think of it as an item place holder

eg.    tHeight &","& tWidth &","& tPrice   where price can be missing, thus
empty.  The last item will not always be the price, but item 3 will be.
-----
This leads to installing your own lineFeed char at the end of strings you
get/make, such as opt-t (†) on a Mac, that will not be confused with part of
the actual value but still be a char in the last item.

fld dataList
32.5,14.0,10.99†
36.0,18.0,†
48.0,12.5,3.99†
,,5.99†
,,†
†
..use.........
put the last item of line 2 of fld dataList into myPrice
Replace "†" with "" in myPrice

Or  
put getLastItem(line 2 of fld dataList) into myPrice
-- function removes the "†" and returns the last item as you think of it

put setLastItem(fld dataList) into fld dataList
-- adds a "†" to every line as you think it should be

--this would also handle the case of 'last line of fld dataList' being
'empty' where the return is the delimiter.  The last line is a real line to
you, but becomes imaginary to Rev if empty.

...and now the last item and the last line always contain something.

Jim Ault
Las Vegas


On 6/4/05 2:56 PM, "Dennis Brown" <see3d at writeme.com> wrote:

> I've finally determined that item delimiters come after the item.
> The last item of a list does not have to have a delimiter --it is
> optional if no more characters in the list.  To keep out of trouble,
> and make cleanup of the last delimiter unnecessary, I always keep the
> trailing delimiter in my lists.  Unfortunately, it is always left off
> when a chunk is returned --even if the last item was empty, meaning
> you lose one item (though an empty one).  You can fix this by always
> appending a delimiter to a returned chunk.  However, in the case
> where you ask for more items than the list has, it will keep the
> trailing delimiter.  You must be vigilant to keep the number of items
> correct in a sparse regular array.  It would take a whole tutorial
> just to explain the proper care and feeding of delimiters.
> 
> Dennis
> 
> 
> On Jun 4, 2005, at 3:15 PM, jbv wrote:
> 
>> Example 1 :
>> 
>> on mouseUp
>>   put "" into L
>>   repeat with i=1 to 5
>>     put i & comma after L
>>   end repeat
>>   put number of items of L
>> end mouseUp
>> 
>> the answer is "5"
>> 
>> ---------------
>> 
>> Example 2 :
>> 
>> on mouseUp
>>   put "" into L
>>   repeat with i=1 to 5
>>     put i & comma after L
>>   end repeat
>>   sort items of L ascending numeric
>>   put number of items of L
>> end mouseUp
>> 
>> the answer is "6"
>> 
>> 
>> Any comment ?
>> 
>> JB
>> 
>> _______________________________________________
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>> 
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list