C # library to import / map ASCII files

This may be a matter of dropping, but I give it a try.

One common task is to import data from ascii files. This is almost always the same as the file structure. Separated by a comma, the line is divided, takes 5 lines, takes 12 ... regardless ... So this is always a different protocol / mapping, but the same processing ...

Is there a library for C # that helps support this everyday scenario?

+4
source share
3 answers

This is awesome: FileHelpers Library

Example:

File:

1732,Juan Perez,435.00,11-05-2002 554,Pedro Gomez,12342.30,06-02-2004 112,Ramiro Politti,0.00,01-02-2000 924,Pablo Ramirez,3321.30,24-11-2002 

Create a class that displays your data.

 [DelimitedRecord(",")] public class Customer { public int CustId; public string Name; public decimal Balance; [FieldConverter(ConverterKind.Date, "dd-MM-yyyy")] public DateTime AddedDate; } 

And then parse with:

 FileHelperEngine engine = new FileHelperEngine(typeof(Customer)); // To Read Use: Customer[] res = engine.ReadFile("FileIn.txt") as Customer[]; // To Write Use: engine.WriteFile("FileOut.txt", res); 

List:

 foreach (Customer cust in res) { Console.WriteLine("Customer Info:"); Console.WriteLine(cust.Name + " - " + cust.AddedDate.ToString("dd/MM/yy")); } 
+4
source

You can take a look at the FileHelpers library .

+1
source

So, the only thing these tasks have is reading a text file?

If FileHelpers is redundant for you (plain text data, etc.), standard .NET classes should be all you need ( String.Split Method , Regex Class , StreamReader Class ).

They provide reading limited to characters ( String.Split ) or strings ( StreamReader ).

+1
source

Source: https://habr.com/ru/post/1342804/


All Articles