How do I parse map data?

The data i want to parse looks something like this:

sdf,dfffffs,safsf,asasrw,re6546eg,dfgert;

gfgr,trt546,rgert,egrg,erg,ergretgreg,erg;

basically its items seperate with a , and they are ended with a ;

i want to make a 2d array out of that.

my pseudocode:

new string array [amountoflines] [amountofitemsinfirstline]

for i=0 to amountoflinesdo (i++)

{

while j>0do

{

while k>0do

{

array[i][j] = array[i][j]+characterat(k);

if("," ) k=-1;

if(";" ) j = -1;

}

}

}

would it work? what kind of methods do you suggest i use?

[1158 byte] By [Comp-Freaka] at [2007-11-27 9:22:55]
# 1
you might want to scan in the line and use the String split method with "," as the separator. That will give you an array of Strings. You can then easily delete the ";" from the last string in the array.
petes1234a at 2007-7-12 22:17:40 > top of Java-index,Java Essentials,Java Programming...
# 2

hi

u can use ArrayList to store a variable length 2D array.

The simplest code that u can think about for this Question, probably is

String inputstr= new String("Sad,asf,sdf,dst;ret,ert,yyt,ryt;ry,tr,yt,ry;");

String[] tmpstr=inputstr.split(";");

ArrayList _2DArray=new ArrayList();

for(int i=0;i<tmpstr.length;i++)_2DArray.add(i,tmpstr.split(","));>

mohammedsajida at 2007-7-12 22:17:40 > top of Java-index,Java Essentials,Java Programming...
# 3

Did i get iit?

// inputstr = the map data

String inputstr= new String("Sad,asf,sdf,dst;ret,ert,yyt,ryt;ry,tr,yt,ry;");

// Creates an array and assigns it like this:

// Line 1 : Sad,asf,sdf,dst; (does it also assign the ";" ?)

// Line 2 : ret,ert,yyt,ryt;

// Line 3 : ry,tr,yt,ry;

String[] tmpstr=inputstr.split(";");

// Defines the "Map" Array

ArrayList _2DArray=new ArrayList();

// Goes through Line 1-3 (mentioned above)

// For each line it:

// Splits the items along the "," and stores them in a 1Dimensilnall String Array

// Ads/Insterts that array into the correct spot for the 2D array

for(int i=0;i<tmpstr.length;i++)_2DArray.add(i,tmpstr.split(","));

Does When it splits test,test1 with "," does it also return the , ?>

Comp-Freaka at 2007-7-12 22:17:40 > top of Java-index,Java Essentials,Java Programming...