Re: reading (parsing) CSV (or Excel) data
Re: reading (parsing) CSV (or Excel) data
- Subject: Re: reading (parsing) CSV (or Excel) data
- From: BareFeet <email@hidden>
- Date: Fri, 2 Oct 2009 10:55:51 +1000
On 02/10/2009, at 10:22 AM, Jens Alfke wrote:
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.
That won't work. CSV can contain commas and newlines within items if
encapsulated in quotes.
The values will be strings not numbers, but you can call -intValue
or -doubleValue on each one to convert it.
Yes, CSV doesn't specify types, just strings, so any interpretation
you make on types is after the actual CSV import.
I found this method (the one under the heading "General CSV"), which
works fine, caters for delimiters within quotes, escaped quotes etc:
http://macresearch.org/cocoa-scientists-part-xxvi-parsing-csv-data
Tom
BareFeet
_______________________________________________
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