Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apostrophe in CSV file #71

Open
rrosendahl opened this issue Nov 1, 2014 · 3 comments
Open

Apostrophe in CSV file #71

rrosendahl opened this issue Nov 1, 2014 · 3 comments

Comments

@rrosendahl
Copy link

Maybe I'm missing something, but I'm parsing a CSV file (from Excel). Everything seems to work well - including parsing fields which contains commas and are embedded in "...": - until the parser comes across the first semicolon (the field is not inside "..."). The parser stops as if it was looking for a 2nd semicolon, which doesn't exist in the file. How do I solve for this? (Excel doesn't see the need to embed cells with semicolons inside "..." when exporting.)

@rrosendahl
Copy link
Author

Okay, interesting. I did some more digging and found out this issue exists with certain characters:

  • 8217 (decimal) - which looks like a semicolon, well, almost
  • ė - french characters.


    Not sure if this is an encoding issue or related?
    BTW: How can one specify the encoding when using
    arrayWithContentsOfDelimitedURL:(NSURL *)fileURL options:(CHCSVParserOptions)options delimiter:(unichar)delimiter ?

@whynoceros
Copy link

Is there a fix or hack to avoid this? I have a .csv which I can't parse beyond the first apostrophe, when I try to use:

rows = [NSMutableArray arrayWithContentsOfCSVURL:pathToFile];

Thanks!

@jomnius
Copy link

jomnius commented Dec 12, 2014

This is how I managed to force encoding, bit awkward but works:

// filename starts with one "/", so add "file://" with only two slashes
NSString *urlPath = [NSString stringWithFormat:@"file://%@", filename];
NSInputStream *stream = [NSInputStream inputStreamWithURL:[NSURL URLWithString:urlPath]];
NSStringEncoding encoding = NSUTF8StringEncoding;
CHCSVParser *p = [[CHCSVParser alloc] initWithInputStream:stream usedEncoding:&encoding delimiter:'\t'];
p.delegate = self;
[p parse];

However I haven't yet been able to fix input syntax problems while parsing, it fails at first (unexpected) unicode character. Still trying, but considering going back to old parser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants