English 中文(简体)
将CSV记录转换为海关数据类型IE(C#)
原标题:Converting CSV records to custom datatype IEnumerable (C#)

I ve got some data inwang CSV form, 他说:

a1,b1
a2,b2
a3,b3

I ve创建了一个班级(CsvRecord),每个班子可以消费一个元素。 利用Linq,I ve得以将CSV数据转换为。 缩略语

IEnumerable<CSVRecord> list = csvList.Select(a => new CSVRecord(a.Split(new char[]{ , })[0], a.Split(new char[]{ , })[1]));

这确实是我所希望的,而只是看一下,这似乎不像实现这一目标的好办法。 请建议我如何改进这项工作?

问题回答

您绝对不想写上自己的CSV教区(如您已查明的),除非您也愿意完全执行RFC 4180标准。 这很可能不是你想要做的事。 有许多不相干的案件。 很幸运的是,执行工作已经存在。

I would use CsvHelper. I ve used it for reading and writing on several occasions and it s always been a good library to use in my experience.

周边有几家有好几家罗姆学生会图书馆。

A good way to improve is take a look at the code out there and if you want to reinvent the wheel as a learning experience, the use these as examples.

然而,如果你只是想起自己的功能,那么就使用原先存在的图书馆。

Check out;

http://www.csvreader.com/ (costs, but is good. You can even buy the source code if needs be). http://www.codeproject.com/KB/database/CsvReader.aspx

我确信,那里也有很多东西。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...