Results 1 to 3 of 3
  1. #1
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Question Split string with the first "!" sign?

    Hello, basically I've got a string "lol1!lol2!lol3"
    And I want to split those in array maximum of 2 so it goes like this:
    t[0] = "lol1"
    t[1] = "lol2!lol3"

    How can I do that?
    (also there are unknown number of those signs I need all the signs to not split and go to t[1] except for the first one...)
    (Without using loops?)
    Last edited by Lionlev; 10-25-2012 at 12:30 AM.
    WARNING I am Russian so it's possible that I wont understand you correctly...

  2. #2
    SJF
    SJF is offline Senior Member
    Join Date
    Oct 2012
    Posts
    108
    Rep Power
    0

    Default Re: Split string with the first "!" sign?

    String.split(String regex, int limit)

    limit = max number of array elements returned.
    Java Code:
     String[] x = "Hi!There".split("e", 2); // x[0] = "Hi!Th", x[1] = "re"

  3. #3
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: Split string with the first "!" sign?

    Oh wow, exactly what I need! Thanks
    rep++
    WARNING I am Russian so it's possible that I wont understand you correctly...

Similar Threads

  1. Replies: 1
    Last Post: 05-07-2012, 05:35 PM
  2. Replies: 14
    Last Post: 04-08-2011, 06:01 PM
  3. string comparison with "=" and ".equal"
    By guavajuice in forum New To Java
    Replies: 9
    Last Post: 04-22-2010, 09:01 PM
  4. Replies: 0
    Last Post: 04-02-2009, 07:02 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

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