Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Need advice on best way to parse strings

800808Jun 2 2011 — edited Jun 15 2011
Hi Java Experts,

I need your advice on the shortest and simplest way to parse the following type of string data from text files, where they will be persisted into database:
Rodney James   20 Olympic Cr  2 children $50,000 IBM
Kelly Julie Furgusion    3 Brooks St  3 children  $80,000 Lehman Brothers Pty Ltd
There are numerous ways to approach this including the following methods:

( i ) Scanner class,
( ii ) String class,
( iii ) A combination of String.split(), Pattern and Matcher.
( iv ) StringTokenizer class,
( v ) StringBuffer

There are many lines on the header and footer of page that should be ignored by testing the number of columns in each row prior to parsing.

The first approach that comes into mine is option ( iii ) and checking the content of each substring using regular expression and looping. This method is quite lengthy and I am wondering whether there is simpler way to achieve it by evaluating the whole string, possibly using regular expressing which I am still grasping.

Your advice would be greatly appreciated.

Thanks,

Jack
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 13 2011
Added on Jun 2 2011
27 comments
696 views