Wtx ~ Wt Extension Library
WtxLib
fastCSV

Fast CSV reader writer in c#.

Features

Usage

1 {c#}
2 public class cars
3 {
4  // you can use fields or properties
5  public string Year;
6  public string Make;
7  public string Model;
8  public string Description;
9  public string Price;
10 }
11 
12 // listcars = List<cars>
13 var listcars = fastCSV.ReadFile<cars>(
14  "csvstandard.csv", // filename
15  true, // has header
16  ',', // delimiter
17  (o, c) => // to object function o : cars object, c : columns array read
18  {
19  o.Year = c[0];
20  o.Make = c[1];
21  o.Model = c[2];
22  o.Description = c[3];
23  o.Price = c[4];
24  // add to list
25  return true;
26  });
27 
28 fastCSV.WriteFile<LocalWeatherData>(
29  "filename2.csv", // filename
30  new string[] { "WBAN", "Date", "SkyCondition" }, // headers
31  '|', // delimiter
32  list, // list of LocalWeatherData to save
33  (o, c) => // from object function
34  {
35  c.Add(o.WBAN);
36  c.Add(o.Date.ToString("yyyyMMdd"));
37  c.Add(o.SkyCondition);
38  });

Helper functions for performance

fastCSV has the following helper functions:

1 {c#}
2 public class LocalWeatherData
3 {
4  public string WBAN;
5  public DateTime Date;
6  public string SkyCondition;
7 }
8 
9 var list = fastCSV.ReadFile<LocalWeatherData>("201503hourly.txt", true, ',', (o, c) =>
10  {
11  bool add = true;
12  o.WBAN = c[0];
13  // c[1] data is in "20150301" format
14  o.Date = new DateTime(fastCSV.ToInt(c[1], 0, 4),
15  fastCSV.ToInt(c[1], 4, 2),
16  fastCSV.ToInt(c[1], 6, 2));
17  o.SkyCondition = c[4];
18  //if (o.Date.Day % 2 == 0)
19  // add = false;
20  return add;
21  });

Performance v1

Loading the https://www.ncdc.noaa.gov/orders/qclcd/QCLCD201503.zip file which has 4,496,263 rows on my machine as a relative comparison to other libraries:

v2

Rewritten the internals:

Performance