Hey everyone,

I am having some trouble parsing a string in java. I get a string from a databse, then I want to put it into a String Array to access two elements in the array (x and y positions). I think my problem is when I try to split the string. Any help would be much appreciated! Thanks!

//String From Database
result = result + c.getString(iRow) + " " + c.getString(iName) + " " + c.getString(iLocation) + "\n";
Example of this: "4 Mango Lane 42194221 -96010225 \n"

result = addSpot.getData();
            String tempA[];
            tempA = result.split(" ");
            tempA = result.split("\n");
            tempA = result.split(",");
            String loc1,loc2;

            for(int i = 3; i < tempA.length; i--) {
                loc1 = tempA[i];
                loc2 = tempA[i];
            x = Integer.parseInt(loc1);
            y = Integer.parseInt(loc2);

Recommended Answers

All 6 Replies

what is the error you have or the output you are receiveing thats wrong/not what you excpect?

I just need to know how to get rid of multiple delimiters in a string, such as a space, "," , etc. Thank you.

Can you post some example Strings that are read in and the results you want to get?

Will do! I will also show what I am doing.

I am getting a string that is delimited by ";".
(i.e) ;My House;236.0;325.00003;My Spot;235.0;356.34562

I want to get this string, spilt it by the ";" then store it in tempA array. I then want to take the x,y coordinates 236.0 325.00003 to use them as pinpoints on a Google Map (This is for an android appliction). The pinpoint works amazing in another part of my app.

result = addSpot.getDataForMap();
String myLocationTest = "";
String tempA[];
tempA = result.split(";");

            String loc1,loc2;

            loc1 = tempA[1].toString();
            loc2 = tempA[2].toString();
            x = Integer.parseInt(loc1);
            y = Integer.parseInt(loc2);
            touchedPoint = map.getProjection().fromPixels(x,y);
            OverlayItem overlayItem = new OverlayItem(touchedPoint, "Hunting Spot", "Nice Spot");
            CustomPinpoint custom = new CustomPinpoint(d, map.this);


What is the contents of the tempA array after the call to split()? Do you need to do another split to get the numbers?
Add a println to show what values are in the TempA array. See the Arrays class's toString() method that will format the array's contents for printing.

What happens when you execute the above code?


The toString() call is redundant since the tempA array is a String array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.