liveBook · Manning

Csv parsing

As explained in .NET in Action, Second Edition

CSV parsing is the process of interpreting comma-separated values text into records and fields while handling delimiters, quoting, and escaping.

CSV parsing interprets delimited text as records and fields. A production importer must handle commas inside quoted fields and escaped double quotes; string.Split(',') cannot do this reliably. section 7.4.1

A reliable implementation follows these decisions:

  • Read the input as a stream, process records, and convert each valid line into a customer object. section 7.4.1
  • Abstract parsing behind an interface so the importer can use a capable NuGet library such as GenericParser or NReco.Csv. section 7.4.1
  • Keep repository operations separate from parsing, allowing parsed customers to be created or updated through an injected repository interface. section 7.4.1

Customer batch importer

CsvImporter receives a Stream, reads lines asynchronously, skips null results, looks up customers by email, and calls CreateAsync or UpdateAsync on the repository. section 7.4.1

How .NET in Action, Second Edition covers it

How deep it goes
Explains why delimiter splitting fails and recommends library-backed abstraction, but does not detail parser internals.
Examples
Uses a customer CSV importer that reads streams and creates or updates customers through a repository.
What it assumes
Assumes familiarity with C# classes, streams, asynchronous methods, interfaces, and repository dependencies.
What you can do after
Apply it via a capable CSV library behind an interface in a streamed customer importer.
How it connects
Connects delimiters, quoting, escaping, interfaces, streams, repositories, and dependency substitution in tests.

Also explained in

Compare how 2 books explain csv parsing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.