This is a CSV (RFC4180) Parser in 100 LOC.
It does not give you spaghetti abstractions like other libraries. The API is simply this:
while (true) {
List<string>? columns = parser.ReadNextRow();
if (columns == null) {
Console.WriteLine("End of file reached");
break;
}
var prettyRow = System.Text.Json.JsonSerializer.Serialize(columns);
Console.WriteLine($"Read row: {prettyRow}");
}
You can easily create your own high level DictReader or whatever extravagance you want, for example supporting an Excel "column groups feature" (multiple headers having the same name, and/or headers with empty names that are expected to inherit the previous header's name), or mapping "NA" and "N/A" to null, etc., which is very far outside the scope of RFC4180.
Install the NuGet Package via:
dotnet add package SmallestCSVParser
-
If you are a human, you may use and modify this code.
-
Copyright © 2024 Karl Pickett
Enjoy 👍