C#CSV文件到数组/列表 [英] C# CSV file to array/list

查看:510
本文介绍了C#CSV文件到数组/列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用C#读取数组中的4-5个CSV文件

I want to read 4-5 CSV files in some array in C#

我知道有人问过这个问题,我已经解决了... 但是我为此使用CSV太简单了...

I know that this question is been asked and I have gone through them... But my use of CSVs is too much simpler for that...

我的csv字段具有以下数据类型的列....

I have csv fiels with columns of following data types....

string , string

这些琴弦没有','所以没有张力... 而已.而且它们并不大.每个记录只有约20条记录.

These strings are without ',' so no tension... That's it. And they aren't much big. Only about 20 records in each.

只是阅读它们到C#数组中....

I just want to read them into array of C#....

有没有非常简单的直接方法来做到这一点?

Is there any very very simple and direct way to do that?

推荐答案

其中包括引号&字段中的逗号. (假设您一次要打一行)

This one includes the quotes & commas in fields. (assumes you're doing a line at a time)

using Microsoft.VisualBasic.FileIO;   //For TextFieldParser

// blah blah blah

StringReader csv_reader = new StringReader(csv_line);

TextFieldParser csv_parser = new TextFieldParser(csv_reader);
csv_parser.SetDelimiters(",");
csv_parser.HasFieldsEnclosedInQuotes = true;
string[] csv_array = csv_parser.ReadFields();

这篇关于C#CSV文件到数组/列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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