FileHelpers:读取文件时如何处理带引号的字段 [英] FileHelpers: How to handle quoted fields when reading file

查看:101
本文介绍了FileHelpers:读取文件时如何处理带引号的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我要读取的数据:

"Adam C. Emality","1Z620Y1V034826","14.40"
"Ethel Baeron","1Z620Y1V034604","15.19"
"Donna Lidt","1Z620Y1V034650","12.37"

然后在读入数据之后,我要对两个集合执行一个Join,一个集合为数组,一个为列表-我的代码在下面.但是,在执行读取的文件行之后,我的字符串就这样存储了"\"Adam C. Emality\"" "\"1Z620Y1V034826\"" "\"14.40\"" ...等.为什么会发生这种情况?我不想包含",也不知道为什么要在\中添加.

Then after reading the data in, I want to perform a Join on the two collections, one an array and one a list - my code below. However after executing the read file line my strings are stored like this "\"Adam C. Emality\"" "\"1Z620Y1V034826\"" "\"14.40\""...etc.. Why is this happening? I do not want to include the " and I don't know why it is adding in a \.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FileHelpers;
using Parser;

namespace Amazon_File
{
    class SpreadSheet
    {
        public void create(IEnumerable<SpreadList> list)
        {


            var steamengine = new FileHelperEngine<Records>();
            var records = steamengine.ReadFile(@"C:\Users\Danny\Documents\Visual Studio 2013\Projects\Amazon File\Amazon File\Daniel.csv");

            var spreadlist = from x in list
                             join y in records on x.Name equals y.Name
                             select new { y.Name, y.Track, y.worldPrice, x.ItemPrice, x.Quantity };



[DelimitedRecord(",")]
    public class Records
    {

        public string Name;

        public string Track;

        public string worldPrice;
    }   

public class SpreadList
    {
        public string Name { get; set; }
        public string Title { get; set; }
        public string ItemPrice { get; set; }
        public string Quantity { get; set; }
    }
}

推荐答案

您必须添加[FieldQuoted]才能使库自动删除它们 http://www.filehelpers.net/docs/html/T_FileHelpers_FieldQuotedAttribute.htm

You must add [FieldQuoted] to make the library auto remove them http://www.filehelpers.net/docs/html/T_FileHelpers_FieldQuotedAttribute.htm

[DelimitedRecord(",")]
public class Records
{
    [FieldQuoted]
    public string Name;

    [FieldQuoted]
    public string Track;

    [FieldQuoted]
    public string worldPrice;
}   

这篇关于FileHelpers:读取文件时如何处理带引号的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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