Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextFieldParser replacement in .net Core 1

In the past, for c# .net MVC projects, I used TextFieldParser from the Visual Basic Reference. Now with .Net Core 1 that no longer seems to be an option. At least I can't figure out how to add the visual basic reference and I imagine if you did wouldn't it make it so it wasn't cross-platform?

The TextFieldParser was great because it covered all of my CSV import needs with great flexibility.

Is there a replacement for the TextFieldParser in .netCore that I am missing? Or is there a way to use the current textfieldparser without breaking cross-platform compatibility?

like image 321
Xaxum Avatar asked Jul 29 '16 02:07

Xaxum


2 Answers

I have just tried CsvHelper - a .NET library for reading and writing CSV files. It covers all needs. Looks fast, flexible and easy to use. Supports reading and writing of custom class objects. It works fine with .NET Core (as it supports .NET Standard 2.0) as well as with .NET Framework 4.5 see dependencies on NuGet page.

like image 183
Dmitry Pavlov Avatar answered Oct 09 '22 21:10

Dmitry Pavlov


For those that need it, TextFieldParser can handle more than just CSV. It supports tab delimited, fixed width fields, etc.

I created a 1 to 1 port of TextFieldParser for .NET Core.

You can get it via nuget by searching for TextFieldParserCore. https://www.nuget.org/packages/TextFieldParserCore/1.0.0

like image 33
datchung Avatar answered Oct 09 '22 21:10

datchung