获取FileHelpers 2.0来处理过剩的逗号CSV文件 [英] Getting FileHelpers 2.0 to handle CSV files with excess commas

查看:144
本文介绍了获取FileHelpers 2.0来处理过剩的逗号CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用的FileHelpers库(V2.0.0.0)解析一个CSV文件。 CSV文件映射到具有公共属性的少数类,假设有 N 。问题是,默认情况下,FileHelpers似乎不正确处理,用户指定比 N-1 逗号更CSV文件的情况。剩下的逗号一下就追加到最后一个属性值。

I am currently using the FileHelpers library (v2.0.0.0) to parse a CSV file. The CSV file is mapped to a class that has a handful of public properties, let's say there are N. The problem is that, by default, FileHelpers doesn't seem to correctly handle cases where the user specifies a CSV file that has more than N-1 commas. The remaining commas just get appended to the last property value.

我想这一定是通过的 FileHelpers'属性的,但我没有看到任何会忽略那些没有在记录匹配的属性字段。

I figured this must be configurable via FileHelpers' attributes, but I didn't see anything that would ignore fields that don't have a matching property in the record.

我看着 RecordCondition S,而是使用类似ExcludeIfEnds( )看起来像它会跳过该行完全,如果它与一个逗号结尾,但我只是希望他们剥离。

I looked into the RecordConditions, but using something like ExcludeIfEnds(",") looks like it will skip the line entirely if it ends with a comma, but I just want them stripped.

这可能是我唯一的办法是预先处理文件,并剥夺任何尾随逗号的这是完全正常的,但我想知道如果FileHelpers能做到这一点为好,也许我只是没有看到它的文档。

It's possible that my only recourse is to pre-process the file and strip any trailing commas, which is totally fine, but I wanted to know if FileHelpers can do this as well, and perhaps I'm just not seeing it in the docs.

推荐答案

只是一个想法为黑客/解决方法:你可以创建一个名为ExtraCommas的属性,并将其添加到您的类,这样额外的逗号序列存在,而不是在你的对象的不动产...

Just an idea for a hack / workaround: you could create a property called "ExtraCommas" and add it to your class, so that extra commas are serialized there and not in the real properties of your object...

这篇关于获取FileHelpers 2.0来处理过剩的逗号CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆