Results 1 to 2 of 2
  1. #1
    issoa is offline Member
    Join Date
    Feb 2012
    Posts
    1
    Rep Power
    0

    Default Splitting the string[]

    i am trying to split the string[] but i could not able to do so, and now sure what i am doing wrong and here is my code:

    String[] songs_array = "Chapter 01>>>one>>>111111:::Chapter 02>>>two>>>222222:::Chapter 03>>>three>>>33333:::Chapter 04>>>four>>>4444:::Chapter 05>>>five>>>5555:::"

    for (int j = 0; j < songs_array.length; j++)
    {
    String[] parts = songs_array[j].split("\\>>>");

    System.out.println("chapter: " + parts[0]);
    System.out.println("title: " + parts[1]);
    System.out.println("code: " + parts[2]);
    }

    so what i want to see in the result is:

    chapter: Chapter 01
    title: one
    code: 111111
    ........
    ...........
    .......

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Splitting the string[]


    first, "Chapter 01>>>one>>>111111:::Chapter 02>>>two>>>222222:::Chapter 03>>>three>>>33333:::Chapter 04>>>four>>>4444:::Chapter 05>>>five>>>5555:::" is a string and not a array of strings
    only split returns a array!
    So you have to split twice.
    Change the first line to
    String[] songs_array = "Chapter 01>>>one>>>111111:::Chapter 02>>>two>>>222222:::Chapter 03>>>three>>>33333:::Chapter 04>>>four>>>4444:::Chapter 05>>>five>>>5555:::".split(":::");
    Or if you dont use split and arrays, you could use Pattern + Matcher

Similar Threads

  1. Java string splitting and concatination
    By mc1234 in forum New To Java
    Replies: 6
    Last Post: 09-26-2011, 03:02 PM
  2. Problem splitting a string
    By sehudson in forum New To Java
    Replies: 2
    Last Post: 03-13-2011, 08:56 PM
  3. Replies: 1
    Last Post: 02-07-2011, 08:22 PM
  4. String Splitting
    By A.M.S in forum New To Java
    Replies: 1
    Last Post: 12-04-2009, 07:17 AM
  5. splitting string and replacing
    By itsme in forum New To Java
    Replies: 1
    Last Post: 12-11-2007, 03:08 PM

Tags for this Thread

Posting Permissions

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