Simple Parsing Question

I’m attempting to take this string “0:0,0|1,1|2,2” and then separate it so that I end up with “0” & “0,0|1,1|2,2” and then separate “0,0|1,1|2,2” into “0,0” “1,1” “2,2” and then separate each of those and place them, in order, into an array.

Here’s what I’ve written so-far:

for(int i=0;i<npcValues.length;i++)
        {
            String[] temp;
            String[] tempTwo;
            temp = waypointValues[i].split(":");
            tempTwo = temp[1].split("|");
            integerValues[i][1][] = tempTwo.split(","); //The waypoints are to be split up and placed, in order, into [i][1][waypointStuffHere] or something like that
            //Parse all info into it's respective array.
        }

The last statement “integerValues[i][1][] = tempTwo.split(”,");" gives an illegal start of expression error and I’m pretty sure it’s because the statement doesn’t work in the way that I think it should be working. I’m not too sure if what I’ve written is going to do what I want as I can’t test it without figuring out how to do the last split so I’ve decided to ask for some help on finishing it up =P

You’re trying to call split() on an array! You need to use a second loop through the tempTwo array.

Ah, that makes sense. ^.^ Here’s the new code:

for(int i=0;i<npcValues.length;i++)
        {
            String[] temp;
            String[] tempTwo;
            temp = waypointValues[i].split(":");
            for(int j=0;j<temp.length;j++)
            {
                tempTwo = temp[j].split("|");
                for(int k=0;k<temp.length;k++)
                {
                    integerValues[i][1][k] = Integer.parseInt(tempTwo[k].toString().split(","));
                }
            }
            //Parse all info into it's respective array.
        }

I’m getting an error on the line “integerValues[i][1][k] = Integer.parseInt(tempTwo[k].toString().split(”,"));" It says that it can’t parse a String[] so I added “.toString()” to turn it into a String instead but the error still shows.

Edit: Switched it to the below and there aren’t any more errors… Time to test it!

for(int i=0;i<npcValues.length;i++)
        {
            String[] temp;
            String[] tempTwo;
            temp = waypointValues[i].split(":");
            for(int j=0;j<temp.length;j++)
            {
                tempTwo = temp[j].split("|");
                for(int k=0;k<temp.length;k++)
                {
                    integerValues[i][1][k] = Integer.valueOf(String.valueOf(tempTwo[k].split(",")));
                }
            }
            //Parse all info into it's respective array.
        }