Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > String Manipulation

Reply
Thread Tools

String Manipulation

 
 
ysoussov@gmail.com
Guest
Posts: n/a
 
      07-13-2007
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?

 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      07-13-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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?
>


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

--

Knute Johnson
email s/nospam/knute/
 
Reply With Quote
 
 
 
 
Tim Slattery
Guest
Posts: n/a
 
      07-13-2007
"(E-Mail Removed)" <(E-Mail Removed)> 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?


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.

--
Tim Slattery
(E-Mail Removed)
http://members.cox.net/slatteryt
 
Reply With Quote
 
Sideswipe
Guest
Posts: n/a
 
      07-13-2007
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, "(E-Mail Removed)" <(E-Mail Removed)> 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?



 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-13-2007
On Fri, 13 Jul 2007 15:57:59 -0000, "(E-Mail Removed)"
<(E-Mail Removed)> 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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-13-2007
On Fri, 13 Jul 2007 15:57:59 -0000, "(E-Mail Removed)"
<(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
String manipulation Chris ASP .Net 1 05-24-2004 02:19 PM
Advanced String Manipulation (C#) Aaron ASP .Net 2 01-02-2004 06:50 PM
String Manipulation Aaron ASP .Net 3 12-31-2003 03:39 PM
Perl string manipulation jared in ecs Perl 2 10-22-2003 05:36 PM
String Array Manipulation Problem Garfield ASP .Net 5 08-27-2003 10:07 PM



Advertisments