Results 1 to 4 of 4
  1. #1
    punk is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Post Splitting Strings

    Please help me split the following string into tokens, I tried using stringtokenizer and split function but couldn't get the correct output. The strings are not constant, I mean the strings are of variable length.

    Below is one of the string -
    <http://data-gov.tw.rpi.edu/raw/8/data-8-00001.rdf#entry1536> <http://data-gov.tw.rpi.edu/vocab/p/8/update_date> "2004-10-27 09:37:21" .

    The output that I got is -
    <http://data-gov.tw.rpi.edu/raw/8/data-8-00001.rdf#entry1536>

    <http://data-gov.tw.rpi.edu/vocab/p/8/update_date>

    "2004-10-27 ----------------- (Problem Lies Here)

    09:37:21"------------------(Problem Lies Here)

    .

    As marked above, I need "2004-10-27 09:37:21" separately in a single string. But according to my splitting program, I am getting "2004-10-27 and 09:37:21" in different strings.

    The ideal output should be something like this -

    <http://data-gov.tw.rpi.edu/raw/8/data-8-00001.rdf#entry1536>

    <http://data-gov.tw.rpi.edu/vocab/p/8/update_date>

    "2004-10-27 09:37:21"

    We can ignore the last . The "." signifies the end of 1 tuple and the begining of the next string. PLease help.

  2. #2
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    10

    Default

    How are we supposed to help? Are you asking for a code segment that will generate this or are you asking for us to fix your code? I don't think you posted it very clearly.

    If you posted your code segment, we could analyze it and see whats causing your problems.

  3. #3
    punk is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default

    I apologize for not explaining my problem clearly, here is my code -

    while ((temp_string = input.readLine()) != null)
    {
    System.out.println(temp_string+"\n");

    String[] tokens = temp_string.split(" ");

    for (int count = 0; count < tokens.length; count++)
    {
    System.out.println(tokens[count]+"\n");
    }
    }
    I know the reason I am getting the output mentioned above is because I am using only space in the split function. I don't really need any code but would really appreciate if you could help me figure out a way around it so that I can get the correct output as mentioned above. Thanks,

  4. #4
    punk is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

Similar Threads

  1. Problem splitting a string
    By sehudson in forum New To Java
    Replies: 2
    Last Post: 03-13-2011, 08:56 PM
  2. Splitting
    By marksey07 in forum New To Java
    Replies: 2
    Last Post: 01-05-2011, 01:55 AM
  3. String Splitting
    By A.M.S in forum New To Java
    Replies: 1
    Last Post: 12-04-2009, 07:17 AM
  4. Reading files and splitting them
    By Dieter in forum Advanced Java
    Replies: 5
    Last Post: 09-30-2009, 09:46 AM
  5. Array splitting
    By Lunarion in forum New To Java
    Replies: 3
    Last Post: 04-17-2009, 08:00 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
  •