String Manipulation

Discussion in 'Java' started by ysoussov@gmail.com, Jul 13, 2007.

  1. Guest

    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?
     
    , Jul 13, 2007
    #1
    1. Advertising

  2. 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/
     
    Knute Johnson, Jul 13, 2007
    #2
    1. Advertising

  3. Tim Slattery Guest

    "" <> 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

    http://members.cox.net/slatteryt
     
    Tim Slattery, Jul 13, 2007
    #3
  4. Sideswipe Guest

    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, "" <> 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?
     
    Sideswipe, Jul 13, 2007
    #4
  5. Roedy Green Guest

    On Fri, 13 Jul 2007 15:57:59 -0000, ""
    <> 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, Jul 13, 2007
    #5
  6. Roedy Green Guest

    On Fri, 13 Jul 2007 15:57:59 -0000, ""
    <> 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
     
    Roedy Green, Jul 13, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jared in ecs

    Perl string manipulation

    jared in ecs, Oct 22, 2003, in forum: Perl
    Replies:
    2
    Views:
    812
    Roy Johnson
    Oct 22, 2003
  2. Garfield

    String Array Manipulation Problem

    Garfield, Aug 27, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    2,820
    Michael Lang
    Aug 27, 2003
  3. Aaron

    String Manipulation

    Aaron, Dec 31, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    4,637
    Dave Davidson
    Dec 31, 2003
  4. Aaron

    Advanced String Manipulation (C#)

    Aaron, Jan 2, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    824
  5. Chris

    String manipulation

    Chris, May 24, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    453
    Pete Wright
    May 24, 2004
Loading...

Share This Page