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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to