Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / April 2004

Tip: Looking for answers? Try searching our database.

Parsing a CSV File

Thread view: 
Shane Mingins - 29 Apr 2004 02:11 GMT
Hi

I have a CSV file that I wish to parse.

A typical line will look like this:

3,,"04-0501",-13000.00,,000,"DE","ATA","","","MR AJ & MRS BJ
SMITH","08/03/2004",04 0501

so I was using String[] statementElements = statementLine.split(","); to
break up each line into the individual elements.

BUT then I found a line like:

3,,"04-0501",-13119.75,,000,"DE","ATA","JONES,SA&DB","FI ZEBBO","ABC
SECURITIES(NZ)","08/03/2004",04 0501

Note the "JONES,SA&DB" though :-(  So split will break that where I do not
want it to do so.

Any ideas or references that would help?

Thanks
Shane

Signature

shanemingins@yahoo.com.duplication
remove duplication
--------------------------------------------------------------------------
"Our thinking was wrong - but our tests were not.  Very interesting..." -
Ron Jefrries

Roedy Green - 29 Apr 2004 03:35 GMT
>I have a CSV file that I wish to parse.
>
>A typical line will look like this:
>
>3,,"04-0501",-13000.00,,000,"DE","ATA","","","MR AJ & MRS BJ
>SMITH","08/03/2004",04 0501

see http://mindprod.com/products.html#CSV

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Real Gagnon - 29 Apr 2004 03:38 GMT
> Any ideas or references that would help?

I'm afraid that the CSV parsing can't be solved with one-line solution
except maybe by a complex regular expression.

However there are many CSV parsers available on the Net.

Here one (not tested) :
http://ostermiller.org/utils/CSV.html

Bye.
Signature

Real Gagnon  from  Quebec, Canada
* Looking for Java or PB snippets ? Visit Real's How-to  
* http://www.rgagnon.com/howto.html

Shane Mingins - 29 Apr 2004 05:09 GMT
Thanks for the references.  I also found:

http://www.objectmentor.com/resources/articles/tfd.pdf

Cheers
Shane

Signature

shanemingins@yahoo.com.duplication
remove duplication
--------------------------------------------------------------------------
"Our thinking was wrong - but our tests were not.  Very interesting..." -
Ron Jefrries

Andrew Thompson - 29 Apr 2004 06:45 GMT
> "Our thinking was wrong - but our tests were not.  Very interesting..." -
> Ron Jefrries

Your spelling was wrong, but Google agrees
with your attribution.  Mildly interesting..

[ Jeffries - two 'f's, one 'r' ]

Signature

Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Shane Mingins - 29 Apr 2004 22:25 GMT
> > "Our thinking was wrong - but our tests were not.  Very interesting..." -
> > Ron Jefrries
[quoted text clipped - 3 lines]
>
> [ Jeffries - two 'f's, one 'r' ]

Opps.  Sorry Ron ;-)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.