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

Parsing "," inside " " Problem #2

Closed
masdevid opened this issue Nov 20, 2014 · 5 comments
Closed

Parsing "," inside " " Problem #2

masdevid opened this issue Nov 20, 2014 · 5 comments
Assignees

Comments

@masdevid
Copy link

Hello, I have a problem when my clients include "," in address field. I use "," as delimiter. So, I couldn't insert a new row because "," inside the address field.
My CSV read file result like this:

0, Name, Address
1, Devid, Working Street Indonesia
2, Devid, "Not working Street, Indonesia"

But, only row 0 and 1 are working to be parsed in JSON.

@bahaaldine bahaaldine self-assigned this Nov 20, 2014
@masdevid
Copy link
Author

I know I can simply change my CSV delimiter as ";", but it would be nice if it can handle "," inside "text"

@bahaaldine
Copy link
Owner

I added support for this kind of use case.

Cheers

883075c

@rondog
Copy link

rondog commented Apr 9, 2015

This seems to work for the content part, but not the JSON part. It returns an empty array. The reason being if ( currentline.length === columnCount ) fails because the column count is defined by content.separator causing it to split inside a quoted string.

It looks to work in your demo, but not on the directive I pulled down with bower

@rondog
Copy link

rondog commented Apr 9, 2015

changing to var columnCount = lines[0].split(content.separator).length; to var columnCount = lines[0].split(new RegExp(content.separator+'(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)')).length; fixed it for me.

@bahaaldine
Copy link
Owner

Hi rondog, you can create pull request :)

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