String Manipulation

Y

ysoussov

Hey everyone, I have a string that is returned from an xml file as two
coordinates for example 23.424242,42.13131 exactly like that with no
spaces, what is a way to break it into two seperate integers?
 
K

Knute Johnson

Hey everyone, I have a string that is returned from an xml file as two
coordinates for example 23.424242,42.13131 exactly like that with no
spaces, what is a way to break it into two seperate integers?

Use String.split() to separate the two numbers. Why you would want to
turn two real numbers into integers I can't imagine.
 
T

Tim Slattery

Hey everyone, I have a string that is returned from an xml file as two
coordinates for example 23.424242,42.13131 exactly like that with no
spaces, what is a way to break it into two seperate integers?

Use the "split" method of the "String" object to break it into two
strings at the comma. Then use Float.parseFloat(....) to convert the
resulting strings to floats. Or Double.parseDouble(....) if you'd
rather use doubles.
 
S

Sideswipe

Alternatively, if you have the ability to change the XML, put them as
two separate fields in the XML. After all, the use of a comma is a
means of overloading the field.
 
R

Roedy Green

Hey everyone, I have a string that is returned from an xml file as two
coordinates for example 23.424242,42.13131 exactly like that with no
spaces, what is a way to break it into two seperate integers?

with a comma separation?

You can break the string with regex split. See
http://mindprod.com/jgloss/regex.html

You can read the file field by field with CSVReader. See
http://mindprod.com/jgloss/csv.html

You can do it with IndexOf( ',') and substring to pick out the two
halves.

You then convert to double using the technique shown you at
http://mindprod.com/applet/converter.html
 
R

Roedy Green

Hey everyone, I have a string that is returned from an xml file as two
coordinates for example 23.424242,42.13131 exactly like that with no
spaces, what is a way to break it into two seperate integers?

If you really meant integers, you have to get rid of the .

You can use String.replace
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top