| Author |
null string & ignore delimeter
|
Jsandy Sandyj
Greenhorn
Joined: Oct 15, 2003
Posts: 5
|
|
I am attempting to break a comma-delimited lines in a file for loading the values into an Oracle database. stringtokenizer is fine for getting hold of the values except where there is a null string between the commas i.e ... 1)how do I check for the null string in a line ? 2) how do I check, if i want to ignore some comma-delimiter with in a line ?
|
 |
Jeff Langr
author
Ranch Hand
Joined: May 14, 2003
Posts: 758
|
|
You might check out the CSV reader utility, located in the resources section of my site. It uses a simplistic state machine implementation, and comes complete with JUnit tests, so it should be relatively easy to tailor to your needs. Regards, Jeff L.
|
Author, Agile Java, Essential Java Style. Agile in a Flash. Contributor, Clean Code.
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
Try the public StringTokenizer(String str, String delim, boolean returnDelims) constructor. I think that will give you all the commas as tokens. It's a little extra work to throw them away, but you won't miss any empty fields. If you really have CSV, take Jeff up on his code. If you look at how Excel or other programs export to CSV, they add quotes around strings or maybe only strings that contain commas. That gets a little tricky.
|
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
|
 |
 |
|
|
subject: null string & ignore delimeter
|
|
|