简体   繁体   English

用带引号的多行字符串解析CSV

[英]Parse CSV with quoted multiline string

I need to parse CSV file that may contain quoted multiline string like below: 我需要解析可能包含带引号的多行字符串的CSV文件,如下所示:

ID;Name;Password;address; phoneNum      
1; "userName"; "userPassword"; "user \n 
    address"; 1234523423

I looked through Commons CSV library's functionality which seems to satisfy the majority of requirements, but it doesn't seem to have an option to read next line in case quotes aren't closed. 我查看了Commons CSV库的功能,该功能似乎可以满足大多数要求,但是在未关闭引号的情况下,它似乎没有读取下一行的选项。

Obviously, if there is a need to use a single quote, it should be screened with an extra pair of double quotes. 显然,如果需要使用单引号,则应使用额外的双引号对进行筛选。

It should work just fine unless there's some bug in the library or misconfiguration. 除非库中存在某些错误或配置错误,否则它应该可以正常工作。 However it might be the case that your password has an unescaped/unclosed quoted field and this not being written properly. 但是,可能是您的密码带有未转义/未关闭的带引号的字段,并且此字段未正确写入。

If that's the situation, give univocity-parsers a try as it has many different options to handle unescaped/unclosed quotes properly. 如果是这种情况,请尝试使用univocity解析器,因为它有许多不同的选项可以正确处理未转义/未关闭的引号。 It is also 4 times faster than Commons CSV. 它也比Commons CSV快4倍。

Disclosure: I'm the author of this library. 披露:我是这个图书馆的作者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM