-
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
-
You can Tokenize the string as long as there are no embedded commas.
http://java.sun.com/j2se/1.3/docs/ap...Tokenizer.html
-
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
-
By Kevin in forum VB Classic
Replies: 3
Last Post: 12-05-2005, 06:25 PM
-
By mike_w in forum VB Classic
Replies: 2
Last Post: 05-22-2005, 11:04 AM
-
By George Gilbert in forum vb.announcements
Replies: 0
Last Post: 08-19-2001, 11:34 AM
-
By Paul in forum Database
Replies: 0
Last Post: 09-02-2000, 08:18 PM
-
By Paul in forum Database
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks