2017-07-25 23 views
1

我是相当新的使用FileHelpers类来解析CSV。我有这样一个文件...忽略FileHelpers中的字段中的NewLIne C#

"background","Info","Agent abcdefg 
    =================== 
    Context Tenant: {Vendor: 1, Customer: 719046046}","2,140.69","","7/11/2017 3:30 AM" 

我想忽略任何换行符,并希望阅读作为一个字符串。你能帮忙吗?

所以在行末是\ r \ n,我希望这个被删除。

+1

File.ReadAllText? – Derek

+0

我很抱歉德里克,那没有工作,或者可能是我不知道如何实施。你能否提供一些代码 – Mahesh

+0

如果字段被正确引用,FileHelpers库应该在字段中支持新行(另见[this](https://stackoverflow.com/questions/11511192/handling-newline-in-delimitedrecord) -with-filehelpers))。看起来您的输入符合此要求。什么不工作?另外,也许你只需要一个'。替换(Environment.NewLine,“”)'你读的字段值? –

回答

1

您可以使用[FieldQuoted]这样的:

public class YourRecordClass 
{ 
    [FieldQuoted()] 
    public string Field1; 

    [FieldQuoted()] 
    public string Field2; 

    [FieldQuoted(QuoteMode.OptionalForBoth, MultiLineMode.AllowForBoth)] 
    public string Field3; 

    [FieldQuoted()] 
    public string Field4; 

    [FieldQuoted()] 
    public string Field5; 

    [FieldQuoted()] 
    public string Field6; 
}