我发现了一个非常棒的库来读取CSV文件 - FileHelpers,但我有一个奇怪的问题。我希望得到一些帮助。提前致谢 !FileHelpers library CSV - 为什么总是从最后一列删除一个字母?
映射后,我总是从右边的最后一列中删除一个字母。
我使用FileHelpers.dll版本2.0.0 - DOTNET的2.0从FileHelpers_2_0_0_bin_docs_wizard.zip
对于例如我有这样一个CSV(一些列报价,但有些没有,它可能会改变)
name;surname
"John";Smith
"Jack";Baker
而且阅读文件,后:
FileHelperEngine<SemicolonsRow> engine = new FileHelperEngine<SemicolonsRow>();
engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;
res = engine.ReadFile("C:\\a.txt");
if (engine.ErrorManager.ErrorCount > 0)
engine.ErrorManager.SaveErrors("C:\\Log.txt");
我得到这个:
res[0].Col0 with name
res[0].Col1 with surnam (lack of e at the end)
res[1].Col0 with John
res[1].Col0 with Smit (lack of h at the end)
当我读取这样的文件:
name;surname;country
"John";Smith;USA
"Jack";Baker;Canada
问题是在第三列 - 所以我得到:countr US Canad
我FileHelpers类:
[IgnoreEmptyLines()]
[DelimitedRecord(";")]
public sealed class SemicolonsRow
{
[FieldOptional()]
[FieldQuoted('"', QuoteMode.OptionalForRead, MultilineMode.AllowForRead)]
public String Col0;
[FieldOptional()]
[FieldQuoted('"', QuoteMode.OptionalForRead, MultilineMode.AllowForRead)]
public String Col1;
[FieldOptional()]
[FieldQuoted('"', QuoteMode.OptionalForRead, MultilineMode.AllowForRead)]
public String Col2;
[FieldOptional()]
[FieldQuoted('"', QuoteMode.OptionalForRead, MultilineMode.AllowForRead)]
public String Col3;
}
任何想法?
当源文件不包含带引号的字段时会发生这种情况吗? – 2012-03-16 22:55:13
@Simon Whittemore - 是的,当我的所有专栏没有任何引号时,我也会得到一些切词。 – Barney 2012-03-17 00:23:09