what form of "split" turns a tab-delimited variable into an array with the first line as keys?

Björnke von Gierke bvg at mac.com
Fri Apr 9 11:56:41 EDT 2010


That the split and combines are useless is completely wrong. I use them all the time and it's a huge timesaver for manipulating x,y matrices. Of course, for the given Task, they do not work for what you want directly. You'll need to change the orientation first, for example thusly:

on mouseUp
   --assuming the example colour and food data from below
   put field 1 into theData
   split theData by column
   repeat with theKey = 1 to the number of lines in the keys of theData
      replace return with tab in theData[theKey]
   end repeat
   combine theData by return
   split theData by return and tab
   put the keys of theData --all done
end mouseUp

Of course a single line solution for switching the orientation of tables would be most handily, because this is really arcane. I'm sure there's other ways that are faster, especially when you only use "repeat for each line in theData" in combination with "put after <endResult>", but you asked about combine and split ;)

Bjoernke

On 9 Apr 2010, at 17:13, Bob Sneidar wrote:

> Just had a few rounds with split and combine, and they are not what you think they are. Split takes the first value in a delimited line and that becomes the key. The rest of the items become the elements. The commands are fairly useless for much of anything. 
> 
> Bob
> 
> 
> On Apr 9, 2010, at 12:07 AM, Josh Mellicker wrote:
> 
>> Given a variable like this, where the first line is "headers":
>> 
>> name  [tab]  color  [tab]  food
>> Trevor  [tab]  green  [tab]  salad
>> Sarah  [tab]  blue  [tab]  pizza
>> Richard  [tab]  orange  [tab]  burgers
>> David  [tab]  purple  [tab]  fruit
>> 
>> What is the best way to turn this into an array, where the array keys are the first line of the variable?
>> 
>> I have tried various forms of "split by" ""split using" and ""split with" but haven't found the right formula. Personally I find the documentation on the various forms of the "split" and "combine" commands a bit scant.


-- 

official ChatRev page:
http://bjoernke.com?target=chatrev

Chat with other RunRev developers:
go stack URL "http://bjoernke.com/chatrev/chatrev1.3b3.rev"




More information about the use-livecode mailing list