I read the CSV file in an array using:
NSString *theWholeTable = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"example" ofType:@"csv"] encoding:NSUTF8StringEncoding error:NULL]; NSArray *tableRows = [theWholeTable componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
And every second object in the array is empty, any idea why?
CSV file data is as follows: 10,156,326,614,1261,1890,3639,5800,10253,20914 20,107,224,422,867,1299,2501,3986,7047,14374
where 10 and 20 are the beginning of each new line.
early.
Edit Instead, I tried using the following code:
NSArray *tableRows = [theWholeTable componentsSeparatedByString:@"\n"];
And it worked the way I wanted it.
Although I'm still not sure why newlineCharacterSet created empty objects ...
Michael campsall
source share