For Programmers: Free Programming Magazines  


Home > Archive > Java Help > April 2004 > Parsing a CSV File









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Parsing a CSV File
Shane Mingins

2004-04-28, 11:04 pm

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



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



Roedy Green

2004-04-29, 1:14 am

On Thu, 29 Apr 2004 13:11:50 +1200, "Shane Mingins"
<shanemingins@yahoo.com.clothes> wrote or quoted :

>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

2004-04-29, 1:14 am

> 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.
--
Real Gagnon from Quebec, Canada
* Looking for Java or PB snippets ? Visit Real's How-to
* http://www.rgagnon.com/howto.html
Shane Mingins

2004-04-29, 1:14 am

Thanks for the references. I also found:

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

Cheers
Shane

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


Andrew Thompson

2004-04-29, 3:33 am

On Thu, 29 Apr 2004 16:09:16 +1200, Shane Mingins wrote:

> "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' ]

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

2004-04-30, 1:21 pm


"Andrew Thompson" <SeeMySites@www.invalid> wrote in message
news:121xm4u1opzqx$.1qzo3qyclofu4$.dlg@40tude.net...
> On Thu, 29 Apr 2004 16:09:16 +1200, Shane Mingins wrote:
>
interesting..." -[color=darkred]
>
> Your spelling was wrong, but Google agrees
> with your attribution. Mildly interesting..
>
> [ Jeffries - two 'f's, one 'r' ]


Opps. Sorry Ron ;-)


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com