HighDots Forums  

Splitting into a multi-dimensional array

Javascript JavaScript language (comp.lang.javascript)


Discuss Splitting into a multi-dimensional array in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
PWGSC/TPSGC
 
Posts: n/a

Default Splitting into a multi-dimensional array - 10-16-2003 , 09:40 AM






I am trying to split a sting into a multi-dimensional array. ex.

value = "lang~1#name~bob#age~37#";

And I want to be able sperate the date to look like

lang = 1
name = bob
age = 37

I was think about having an array created that would be:

value[0][0] = lang
value[0][1] = 1

value[1][0] = name
value[1][1] = bob


value[2][0] = age
value[2][1] = 37

But an open to ideas, drawing a little bit of a mind blank...



Reply With Quote
  #2  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: Splitting into a multi-dimensional array - 10-16-2003 , 10:35 AM






PWGSC/TPSGC wrote:
^^^^^^^^^^^
A quite unusual name.

Quote:
I am trying to split a sting into a multi-dimensional array. ex.

value = "lang~1#name~bob#age~37#";
[...]
I was think about having an array created that would be:

value[0][0] = lang
value[0][1] = 1

value[1][0] = name
value[1][1] = bob

value[2][0] = age
value[2][1] = 37

But an open to ideas, drawing a little bit of a mind blank...
Quickhack:

value = value.split("#");
for (var i = 0; i < value.length; i++)
{
var tmp = value[i].split("~");
value[i] = new Array();
for (var j = 0; j < tmp.length; j++)
value[i][j] = tmp[j];
}

But a simple object seems to be better than an Array object:

value = value.split("#");
for (var i = 0; i < value.length; i++)
{
var tmp = value[i].split("~");
value[tmp[0]] = tmp[1];
}


PointedEars



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.