File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes null string & ignore delimeter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "null string & ignore delimeter" Watch "null string & ignore delimeter" New topic

null string & ignore delimeter

Jsandy Sandyj

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
Ranch Hand

Joined: May 14, 2003
Posts: 799
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.
Jeff L.

Books: Pragmatic Unit Testing in Java, Agile Java, Modern C++ Programming with TDD, 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
I agree. Here's the link:
subject: null string & ignore delimeter
It's not a secret anymore!