Results 1 to 7 of 7

Thread: .split()

  1. #1
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Question .split()

    Hi everyone,

    I have a little bit of problems with the .split() funtion.
    To make things short, I have this lines with words like: A.HelloWorld.D
    Now there are also words that have: A.HelloWorld.

    What I would like is that when there is nothing after the second dot (.) that the program will print a " ". But I don't know how to do that?

    Becose I also would like to do something with it outside the if else part.

    Thanks,
    Lund

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,987
    Rep Power
    9

    Default

    Sounds like a job for replaceAll().
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    There's also a two argument split( ... ) method (it's API doc description is below the one argument split( ... ) method). It can do the job ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default

    I found the solution!
    Thanks for the help. :-)
    Last edited by Lund01; 06-27-2011 at 07:08 PM.

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Quote Originally Posted by Lund01 View Post
    I found the solution!
    Where was it hiding?

  6. #6
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default

    I needed a -1 behind it.
    Like .split("\\.", -1)
    And then he also sees the 'blank' spaces.

  7. #7
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    392
    Rep Power
    4

    Default

    If the line before the second dot is always the same, you could also use .substring to get the remainder. It'd mean that you'd have to change the code if the input changes though, which isn't always optimal.

Similar Threads

  1. How to use split?
    By jeff_limsy in forum New To Java
    Replies: 3
    Last Post: 12-29-2010, 09:23 AM
  2. Split a String with split()--Help
    By danilson in forum New To Java
    Replies: 7
    Last Post: 11-19-2010, 04:08 PM
  3. How to split a String using split function
    By Java Tip in forum java.lang
    Replies: 4
    Last Post: 04-17-2009, 08:27 PM
  4. How to split a String using split function
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 10-04-2007, 09:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •