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.
Quick way to do this:
NSString *dataStr = [NSString stringWithContentsOfFile:@"example.csv" encoding:NSUTF8StringEncoding error:nil];
NSArray *array = [dataStr componentsSeparatedByString: @","];
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.
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.
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.
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.