开发者

Modify CSV Parser to work with TSV files C#

I have this code for parsing a CSV file.

var query = from line in File.ReadAllLines("E:/test/sales/" + filename)
                        let customerRecord = line.Split(',')
                开发者_如何学运维        select new FTPSalesDetails
                        {
                            retailerName = "Example",
                        };

            foreach (var item in query)
            {
                //sales details table
                ItemSale ts = new ItemSale
                {
                    RetailerID = GetRetailerID(item.retailerName)  
                };
            }

Obviously there will be more data in the above code, I am just awaiting the test information file details/structure.

In the mean time I thought I'd ask if this could me modified to parse TSV files?

All help is appreciated,

thanks :)


assuming tsv is tab separated value, you can use

line.Split('\t')

if you are using .NET 4.0, i would recommend that u use File.ReadLines for large files in order to use LINQ and not to load all the lines in memory at once.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜