1

I am working on a iphone project . I want to parse a CSV file. From whatever I found, the

libraries available for CSV parsing is only for MAC , not for iphone. I want a simple approach

for parsing CSV file only for iphone. Any help is greatly appreciated

pldoverflow
  • 869
  • 6
  • 10
Raj
  • 1,119
  • 1
  • 15
  • 32
  • See: [Where can I find a CSV to NSArray parser for Objective-C?](http://stackoverflow.com/q/3344628/1402846). – Pang Jan 23 '13 at 07:05

2 Answers2

4

This is a nice CSV parser with support for streams: https://github.com/davedelong/CHCSVParser

If you are parsing a file that comes from the web, then you could also use https://github.com/acerbetti/AFCSVRequestOperation which is using the AFNetworking library for downloading the file.

Edwin Vermeer
  • 13,017
  • 2
  • 34
  • 58
0

CSV is basically a comma separated list of values. You can use NSString methods componentsSeparatedByString: or componentsSeparatedByCharactersInSet: for that.

Suppose you have a comma separated string, calling [myStringCSV componentsSeparatedByString:@","] will give you an NSArray with the values.

pldoverflow
  • 869
  • 6
  • 10
  • 3
    This is an oversimplification - what will componentsSeparatedByString method do with this perfectly valid CSV: string, "another,string"? Make three elements out of two! You'd better use a library that knows how to manage all the corner cases like the one suggested by Edwin Vermeer: CHCSVParser. – Tomasz Stanczak Jan 23 '13 at 07:37
  • Just filter out empty elements, no big deal. – pldoverflow Jan 23 '13 at 16:56