Results 1 to 3 of 3
  1. #1
    counterfox is offline Member
    Join Date
    Mar 2009
    Posts
    45
    Rep Power
    0

    Default String split method

    Hi I'm just trying to do multiple splits on a String. For example:

    Java Code:
    String str =“My numbers;number1,number2;number3,number4;number5,number6”
    String[] saveData;
    saveData = str.split(";");
    I belive this will in the array make

    “Name” “number1,number2” “number3,number4” “number5,number6”

    Im guessing now the array will be indexed from 0 - 3.

    But im confused with now is how would I store a split of all these eg. split(",")
    so I get "name" "number1" "number2" "number3" "number4" "number5" "number6"

    Can anyone please help me with this code.

    thanks

  2. #2
    venerik is offline Member
    Join Date
    Oct 2010
    Posts
    94
    Rep Power
    0

    Default

    You can use a regular expression for that. Basically you are already doing that (i.e. "," is the regex). By using "[,;]" as the regex the split method will look for , or ; to split.

    Cheers,
    Erik
    I'm new to Java but I like to help where ever I can. :)

  3. #3
    counterfox is offline Member
    Join Date
    Mar 2009
    Posts
    45
    Rep Power
    0

Similar Threads

  1. Using String Split
    By JonJacobs in forum New To Java
    Replies: 5
    Last Post: 07-27-2010, 07:43 PM
  2. String Split
    By sarovarc in forum New To Java
    Replies: 6
    Last Post: 04-19-2010, 05:06 AM
  3. Please help me with Split method> String
    By javanew in forum New To Java
    Replies: 5
    Last Post: 04-02-2010, 06:15 PM
  4. 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
  5. 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
  •