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?
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(","));>
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 , ?>