wood burning stoves*
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
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: 762
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.


Books: 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: null string & ignore delimeter
 
Similar Threads
Regular expression required
Need help in regular expressions
check values in a csv file in all files in a directory
StreamTokenizer usage
string.replace()