Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to split CSV fields with embedded commas? 2

Status
Not open for further replies.

terryISO

Programmer
Sep 29, 2002
48
GB
Hi.

I have a set of comma separated files which I need to split into arrays. The problem is that the format of the file is mixed text and numeric. The text fileds are double quoted, and may have commas inside! The numbers are not double quoted. Also, som fields are empty. (not even a space between the commas).

So what I start with will be like this:

"field 1",2.32,"Field 3 has commas, etc",,"Field 5"

And I want to end up with:
$var[0]="field 1"
$var[2]="2.32"
$var[3]="Field 3 has commas, etc"
$var[4]=""
$var[5]="Field 5"

and so on. (with the quotes stripped off). I can do this in a time consuming way, but can anyone advise me of a quick method (I have to decode about a million CSV fields per run for this project, and my existing code takes about 3 hours).

Many thanks.
 
Rosenk, thank you!

That was exactly what I was after.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top