Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null string & ignore delimeter

 
Jsandy Sandyj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 799
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic