Arrays in Rev

Ken Ray kray at sonsothunder.com
Sat Dec 11 14:10:52 EST 2004


On 12/11/04 8:17 AM, "Alex Tweedly" <alex at tweedly.net> wrote:

>> Revolution:
>>   put "1,Troy,Ken,Richard"&cr&"2,Kevin,Jan,Judy" into myList
>>   split myList by CR and ","
>>   put myList[2] into tempArray
>>   --> Kevin,Jan,Judy
>>   split tempArray by ","
>>   put tempArray[1]
>>   --> Kevin
>> 
>> But note that this is NOT usually something you'd do in Rev... Director is
>> designed to be able to make arrays of arrays, and although Rev can simulate
>> this, it is not the most efficient, nor is it the best approach. One reason
>> is that if you'll notice, I had to add line numbers before each line in
>> myList so that when I used 'split' I could reference the array by number.
>> Why? Because remember that no matter what it may appear to be, Rev uses
>> associative arrays ONLY - myList[1] is NOT numeric... it is creating a
>> *string* called "1" that is associated with the value that you give it.
> 
> I don't get it. You need the second "split" to split up the entries Kevin
> and Jan and Judy - so why use the second delimiter in the first split.
> Couldn't you just do ....
> 
> Revolution:
>    put "Troy,Ken,Richard"&cr&"Kevin,Jan,Judy" into myList   -- NB no numbers
> !!
>    split myList by CR     -- note - no second delimiter
>    put myList[2] into tempArray
>    --> Kevin,Jan,Judy
>    split tempArray by ","
>    put tempArray[1]
>    --> Kevin

Good catch! That would certainly be easier. However the first way is useful
if for some reason you don't have the list in order (since having the
numbers in front will *definitely* put it into the right element, regardless
of the order of the lines).


Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com




More information about the use-livecode mailing list