https://github.com/eliotjones/csvswan
Easily parse CSV files from C# using common defaults
https://github.com/eliotjones/csvswan
csharp csv csv-parser csv-parsing csv-reader
Last synced: 5 months ago
JSON representation
Easily parse CSV files from C# using common defaults
- Host: GitHub
- URL: https://github.com/eliotjones/csvswan
- Owner: EliotJones
- License: mit
- Created: 2020-02-09T17:36:07.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-21T13:02:10.000Z (over 3 years ago)
- Last Synced: 2025-08-01T02:39:35.619Z (6 months ago)
- Topics: csharp, csv, csv-parser, csv-parsing, csv-reader
- Language: C#
- Size: 109 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CSV Swan #

CsvSwan is a small .NET Standard CSV parsing library that "just works" for the simplest CSV scenarios. It aims to be high-performance and provide easy-to-use defaults.
using (Csv csv = Csv.Open(@"C:\path\to\file.csv"))
{
foreach (var row in csv.Rows)
{
// Get all values
IReadOnlyList values = row.GetValues();
// Map to a numeric type
int id = row.GetInt(0);
decimal value = row.GetDecimal(1);
}
}
You can also map to a list of objects of a given type:
public class MyClass
{
[CsvColumnOrder(0)]
public int Id { get; set; }
[CsvColumnOrder(1)]
public string Name { get; set; }
}
using (Csv cvs = Csv.Open(@"C:\path\to\file.csv"))
{
List results = csv.Map().ToList();
}
The default settings are for a file with:
+ A comma separator `,`.
+ Newlines between rows, either Unix `\n` or Windows `\r\n`.
+ Optional quotes using the double quote `"` for fields.
+ Quotes inside quoted fields escaped using either RFC-4180 double-double quotes `""` (or optionally backslash escaped `\"`, use `CsvOptions.BackslashEscapesQuotes`, off by default).
Additionally the user must specify if the file contains a header row prior to parsing using `CsvOptions.HasHeaderRow`, this is off by default.
The separator and quote character can be set to other values using the `CsvOptions` parameter to the `Csv.Open` methods.
## Installation ##
Get it from [NuGet](https://www.nuget.org/packages/CsvSwan) or install from the package manager command line:
> Install-Package CsvSwan