davedelong/CHCSVParser

Option to specify delimiter in convenience method

sebromero opened this issue · 4 comments

It would be fantastic if we could have a method like the following

[NSArray arrayWithContentsOfCSVFile:fileURL.path delimiter:@";"]

Now I had to implement a custom class as the parser delegate because the _CHCSVAggregator is a private class. I did it like this:

SCSVAggregator* semicolonSeparatedAggregator = [[SCSVAggregator alloc] init];
NSInputStream *stream = [NSInputStream inputStreamWithFileAtPath:fileURL.path];
NSStringEncoding encoding = 0;
CHCSVParser* semicolonSeparatedParser = [[CHCSVParser alloc] initWithInputStream:stream usedEncoding:&encoding delimiter:';'];
semicolonSeparatedParser.delegate = semicolonSeparatedAggregator;
[semicolonSeparatedParser parse];

Has there been any progress with this issue at all? I'm also having trouble figuring out how to use an alternative delimiter pushing out to an NSArray.

@ed-parry: This functionality exists in the parser; there's just not an easy "one-liner" for it. To use a custom delimiter, you'll have to set up an delegate for the CHCSVParser and have it aggregate the strings. For example, this is how the existing convenience methods are implemented.

But no, I have not been working on this at all. I'm extremely busy.

This is in now. Enjoy.

Fantastic! Thank you, @davedelong and also @yconst!