Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

String Manipulation

Thread view: 
ysoussov@gmail.com - 13 Jul 2007 16:57 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?
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.