Re: reading (parsing) CSV (or Excel) data
Re: reading (parsing) CSV (or Excel) data
- Subject: Re: reading (parsing) CSV (or Excel) data
- From: Rick Genter <email@hidden>
- Date: Thu, 1 Oct 2009 18:08:08 -0700
On Oct 1, 2009, at 5:22 PM, Jens Alfke wrote:
On Oct 1, 2009, at 4:09 PM, Colin Howarth wrote:
Before I go through the 550,000 hits (some of them quite old) dare
I ask if there's one Right Way (TM) to parse this sort of data?
If the data's not too huge, you can read the file into an NSString,
break that into lines (there are some NSString methods for this, but
I don't remember their names), and then on each line call [line
componentsSeparatedByString: @","] to get the values in an NSArray.
The values will be strings not numbers, but you can call -intValue
or -doubleValue on each one to convert it.
As has been pointed out, .csv files are not quite that simple.
The .csv format is actually an official RFC (RFC-4180). .csv is not
very difficult to parse, but there are some subtleties around the
quoting and newlines:
http://www.rfc-editor.org/rfc/rfc4180.txt
I don't know whether Excel strictly adheres to the RFC, but a .csv
parser that I wrote a number of years ago that follows the RFC has so
far been quite successful parsing Excel-generated .csvs without
complaint.
--
Rick Genter
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden