我發現了一個非常棒的庫來讀取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