此有效CSV是否已转义? Lumenworks抛出一个异常,但其他解析器似乎工作

时间:2014-01-23 16:38:51

标签: csv lumenworks

我正在更新解析CSV的遗留系统。我决定使用LumenWorks csv库。它在这样的记录上挣扎:

"Cats","123","A","B","Mittens","1","2","3","1950",""PROBLEM IS HERE"","Some street","Fishtown","","AB13DF","United Kingdom","","","","","","","United Kingdom","Fiddles"

据我所知,这应该作为"""PROBLEM IS HERE"""进行转义。谁能确认一下?如果它有效,那么我需要找到一个修复程序,但如果不是,我可以通知客户端他们提供的CSV格式不正确。

此外,如果有一种方法可以使用LumenWorks(理想情况下是一种非黑客方式)来阻止它抛出异常,那就太好了。谢谢!

我应该补充一点,LumenWorks给了我这个:LumenWorks.Framework.IO.Csv.MalformedCsvException: The CSV appears to be corrupt near record ...

1 个答案:

答案 0 :(得分:3)

虽然Lumenworks网站未指定它符合RFC 4180,但当前预期的转义指定为:

  

7。如果使用双引号括起字段,则使用双引号   出现在一个字段内必须通过前面的方式进行转义   另一个双引号。例如:

"aaa","b""bb","ccc"

因此,要包含字符串"PROBLEM IS HERE",您需要将引号加倍,生成""PROBLEM IS HERE"",然后将其括在双引号中,生成"""PROBLEM IS HERE"""