How do I use comma-separated-value file received from a URL query in Objective-c? when I query the URL I get csv such as "OMRUAH=X",20.741,"3/16/2010","1:52pm",20.7226,20.7594. How do I capture and use this for my application? My problem is creating/initializing that NSString object in the first place. An example is this link "http://download.finance.yahoo.com/d/quotes.csv?s=GBPEUR=X&f=sl1d1t1ba&e=.csv" which returns csv. I dont know how to capture this as an object since I cannot use an NSXMLParser object.
views:
82answers:
2
A:
a couple tools:
http://michael.stapelberg.de/cCSVParse
http://www.cocoadev.com/index.pl?ReadWriteCSVAndTSV
Here's an example of using NSScanner: http://www.macresearch.org/cocoa-scientists-part-xxvi-parsing-csv-data
+1
A:
You can try the following code using -componentsSeparatedByString:
which will end up with an NSArray of each component separated by:
NSURL *url = [NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=GBPEUR=X&f=sl1d1t1ba&e=.csv"];
NSString *reply = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:nil];
NSArray *csvItems = [reply componentsSeparatedByString:@","];
Claus
Claus Broch
2010-03-17 21:31:08