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?
Knute Johnson - 13 Jul 2007 17:22 GMT
> 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.

Signature
Knute Johnson
email s/nospam/knute/
Tim Slattery - 13 Jul 2007 17:27 GMT
>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.

Signature
Tim Slattery
Slattery_T@bls.gov
http://members.cox.net/slatteryt
Sideswipe - 13 Jul 2007 19:47 GMT
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.
On Jul 13, 8:57 am, "ysous...@gmail.com" <ysous...@gmail.com> wrote:
> 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?
Roedy Green - 13 Jul 2007 20:46 GMT
On Fri, 13 Jul 2007 15:57:59 -0000, "ysoussov@gmail.com"
<ysoussov@gmail.com> wrote, quoted or indirectly quoted someone who
said :
>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
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Roedy Green - 13 Jul 2007 20:47 GMT
On Fri, 13 Jul 2007 15:57:59 -0000, "ysoussov@gmail.com"
<ysoussov@gmail.com> wrote, quoted or indirectly quoted someone who
said :
>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
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com