Java: parse data from text file question


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Java: parse data from text file question

  1. #1
    Join Date
    Jan 2006
    Posts
    1

    Red face Java: parse data from text file question

    [SIZE=5]Hello, my name is Jay. I have taken a course in Java, and written several simple programs. I am a little bit rusty on the parse function,
    what I am wanting to do is take data in text file format, parse the data, and output it in the following format

    title firstName middleInitial lastName
    streetAddress
    city, state zip

    I want to export it into a new text file like that. All other data can be disregaurded at this point.
    I know how to do all of the file I/O stuff, but as I said, I am not really sure how to parse the data and put it in that format.
    any help would be very much appreciated. This is my first on the job assignment as a programmer, so I want to make sure I can get it working.

    here is the EXACT format of the original text file:

    "fullName", "title", "firstName", "lastName", "middleInitial", "streetAddress", "city", "state", "zip", "phoneNumber", "Age", "income"
    "fullName", "title", "firstName", "lastName", "middleInitial", "streetAddress", "city", "state", "zip", "phoneNumber", "Age", "income"
    "fullName", "title", "firstName", "lastName", "middleInitial", "streetAddress", "city", "state", "zip", "phoneNumber", "Age", "income"
    "fullName", "title", "firstName", "lastName", "middleInitial", "streetAddress", "city", "state", "zip", "phoneNumber", "Age", "income"
    "fullName", "title", "firstName", "lastName", "middleInitial", "streetAddress", "city", "state", "zip", "phoneNumber", "Age", "income"
    Thanks again.

    -jay

  2. #2
    Join Date
    Jun 2004
    Posts
    199
    You can Tokenize the string as long as there are no embedded commas.

    http://java.sun.com/j2se/1.3/docs/ap...Tokenizer.html

  3. #3
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Use the String replace function to set all the apostrophes to blank (' ').
    Use the String split() function for splitting up the records at the commas. Then use the String trim() function for each of the elements in the array returned from the split operation, and then you do the output.

    Just remember: this operation

    String s= "abcd";
    s.replace('a','x');

    will not make the string s = "xabc".

    This operation will

    s=s.replace('a','x');

    I just wanted to mention it, as I have seen many new java programmers go into that trap with a big "huh ?"
    Last edited by sjalle; 01-09-2006 at 12:16 PM.
    eschew obfuscation

Similar Threads

  1. Importing text file using schema.ini
    By Kevin in forum VB Classic
    Replies: 3
    Last Post: 12-05-2005, 06:25 PM
  2. Loading data from a file to text boxs
    By mike_w in forum VB Classic
    Replies: 2
    Last Post: 05-22-2005, 11:04 AM
  3. Double Text 1.0
    By George Gilbert in forum vb.announcements
    Replies: 0
    Last Post: 08-19-2001, 11:34 AM
  4. Replies: 0
    Last Post: 09-02-2000, 08:18 PM
  5. Replies: 0
    Last Post: 08-22-2000, 10:54 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center