将CSV文件导入到.Net中的强类型数据结构 [英] Import CSV file to strongly typed data structure in .Net
问题描述
将CSV文件导入强类型数据结构的最佳方法是什么?
What's the best way to import a CSV file into a strongly-typed data structure?
推荐答案
Microsoft的 TextFieldParser 是稳定的,对于CSV文件,遵循 RFC 4180 .不要被Microsoft.VisualBasic
命名空间推迟;它是.NET Framework中的标准组件,只需添加对全局Microsoft.VisualBasic
程序集的引用即可.
Microsoft's TextFieldParser is stable and follows RFC 4180 for CSV files. Don't be put off by the Microsoft.VisualBasic
namespace; it's a standard component in the .NET Framework, just add a reference to the global Microsoft.VisualBasic
assembly.
如果您正在为Windows(而不是Mono)编译,并且不希望解析破碎的"(不符合RFC的)CSV文件,那么这将是显而易见的选择,因为它是免费的,不受限制的,稳定且受到积极支持,对于FileHelpers来说,绝不能说很多.
If you're compiling for Windows (as opposed to Mono) and don't anticipate having to parse "broken" (non-RFC-compliant) CSV files, then this would be the obvious choice, as it's free, unrestricted, stable, and actively supported, most of which cannot be said for FileHelpers.
另请参阅:如何:从Visual Basic中读取逗号分隔的文本文件以获取VB代码示例.
See also: How to: Read From Comma-Delimited Text Files in Visual Basic for a VB code example.
这篇关于将CSV文件导入到.Net中的强类型数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!