views:

159

answers:

5

I'm looking for an easy to use csv parser for objective-c to use on the iphone? I'm also looking for other parsers such as json so maybe there is a conversion library somewhere.

+1  A: 

Quick way to do this:

NSString *dataStr = [NSString stringWithContentsOfFile:@"example.csv" encoding:NSUTF8StringEncoding error:nil];
NSArray *array = [dataStr componentsSeparatedByString: @","];

xmr
This wont handle blocks containing ,'s though which is why you often need a fully fledged library :)
willcodejavaforfood
not what I need today, but good to know about that method/message(?)
Toby Allen
A: 

I've found ParseKit few weeks ago But IMHO for most cases -[NSString componentsSeparatedByString:] method and NSScanner are more than enough and quite easy to use.

OgreSwamp
thanks, looks a bit complex for what I'm looking for though.
Toby Allen
+1  A: 

I wrote a dead-simple (although not fully-featured) CSV parser for a project I was working on: CSVFile.h and CSVFile.m. Feel free to grab it -- the code is available under the GPLv3 (unfortunately, it was a requirement for the project I was working on) but I'd be happy to license it to you under an MIT license or another license.

mipadi
A: 

This seems to be the most comprehensive that I've found so far.

http://www.macresearch.org/cocoa-scientists-part-xxvi-parsing-csv-data

As a side note, you'd think most major languages (Delphi, C#, Objective-c, php etc) would have a library available with a full implementation of this basic data interchange format.

I know json is cool and XML is reliable but neither are available as a save option from most applications saving table data. CSV still is.

Toby Allen
+6  A: 

I finally got around to cleaning up a parser I've had in my code folder and posted it on Github: http://github.com/davedelong/CHCSVParser

It's quite thorough. It handles all sorts of escaping schemes, newlines in fields, comments, etc. It also uses intelligent file loading, which means you can safely parse huge files in constrained memory conditions.

Dave DeLong