Results 1 to 4 of 4
  1. #1
    meshhat is offline Member
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Default parsing multiple delimiters

    I have to input and parse the contents of a .txt file. I can do this using Scanner class and defining a delimiter (e.g. scanner.useDelimiter(",");)
    However, my txt file has multiple delimiters. For example, this is a snippet of the file:

    Question: Question text goes here Location: Chicago, IL School: Unit 5 Grade: 8 Question: Question 2 text goes here Location: Inglewood, CA School: Ben Franklin Elementary Grade: 4

    So, basically, there are numerous delimiters (Question:, Location: School:, etc) and nothing that indicates the start of a new question. Note, I can't use : as a delimiter as it often appears in the text as a legitimate character

    Can someone inform me on the best way to parse using multiple delimiters so it reads:
    Question: Question Text
    Location: Chicago, IL
    School:
    Grade: 8


    Question: Question Text
    Location: Inglewood, CA
    School:
    Grade: 4


    thank you

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    You'll need to just tokenize it and manually work through it. The delimiters you want to look for are "Question: ", "Location: ", etc.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

  4. #4
    paras is offline Member
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Default

    another way to do this is by implementing serializable
    so that your stored data can be stored in an arraylist

Similar Threads

  1. Read file delimiters
    By GraemeH in forum New To Java
    Replies: 4
    Last Post: 03-29-2009, 11:44 AM
  2. Xml Parsing
    By Nomad in forum XML
    Replies: 12
    Last Post: 02-22-2009, 11:19 AM
  3. xml parsing
    By gaurav65176 in forum XML
    Replies: 5
    Last Post: 11-12-2008, 11:07 AM
  4. Replies: 4
    Last Post: 07-07-2008, 01:32 PM
  5. Parsing URL
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-26-2007, 10:16 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
  •