From c5f5e0ccd3077f4f7ec12d62117d849aef9b9ee6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vict=C3=B3ria=20Rose?=
<70824102+victoriaquasar@users.noreply.github.com>
Date: Fri, 7 Oct 2022 18:05:41 -0300
Subject: [PATCH] readme: improved code examples readability
---
README.md | 66 +++++++++++++++++++++++++++++++------------------------
1 file changed, 37 insertions(+), 29 deletions(-)
diff --git a/README.md b/README.md
index a0f5d99..bce1fbf 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-##C# project for reading and writing CSVs
+## DataTable
Fast streaming CSV parser. Libraries for easy reading, writing, and manipulation of CSV files. Is able to handle:
@@ -12,52 +12,60 @@ Fast streaming CSV parser. Libraries for easy reading, writing, and manipulation
It's an easier data table than `System.Data.DataTable`.
+
+
The following nuget packages are available:
* [CsvTools](https://www.nuget.org/packages/CsvTools) - the base library
* [CsvTools.Excel](https://www.nuget.org/packages/CsvTools.Excel) - dependency on CsvTools and the OpenXml SDK
+
+
A few quick examples:
> **Download as CsvTools from Nuget to include in your C# project**:
-
- using DataAccess;
- // See methods on DataTable.New for loading a DataTable.
- var dt = DataTable.New.ReadLazy(filename); // Fast streaming load a CSV from disk.
+```cs
+using DataAccess; // See methods on DataTable.New for loading a DataTable.
+var dt = DataTable.New.ReadLazy(filename); // Fast streaming load a CSV from disk.
+```
> **Get a mutable datatable**:
+```cs
+MutableDataTable dt = DataTable.New.ReadCsv(filename); // load entire CSV into memory for mutation
+int totalRows = dt.NumRows;
- MutableDataTable dt = DataTable.New.ReadCsv(filename); // load entire CSV into memory for mutation
- int totalRows = dt.NumRows;
+// Includes mutation methods like:
+// CreateColumn, ReorderColumn, KeepColumns, RenameColumn,
+// GetRow(int rowIndex), KeepRows(Func predicate)
- // Includes mutation methods like:
- // CreateColumn, ReorderColumn, KeepColumns, RenameColumn,
- // GetRow(int rowIndex), KeepRows(Func predicate)
-
- dt.SaveCsv(filename); // write back out
+dt.SaveCsv(filename); // write back out
+```
> **Linq against the rows**:
-
- var y = from row in dt.Rows where row["N"] == "3" select row["NSquared"];
+```cs
+var y = from row in dt.Rows where row["N"] == "3" select row["NSquared"];
+```
> **Linq with strongly-typed parsing, using `RowAs()` method**:
-
- class Entry
- {
- public int N { get; set; }
- public int NSquared { get; set; }
- }
- int y = (from row in dt.RowsAs() where row.N == 3 select row.NSquared).First();
+```
+class Entry
+{
+ public int N { get; set; }
+ public int NSquared { get; set; }
+}
+int y = (from row in dt.RowsAs() where row.N == 3 select row.NSquared).First();
+```
> **Create a table around an `IEnumerable` and then save back as a CSV**:
-
- var x = from i in Enumerable.Range(1, 5) select new { N = i, NSquared = i * i };
- DataTable dt = DataTable.New.FromEnumerable(x);
- dt.SaveToStream(Console.Out); // write back out as a CSV
+```cs
+var x = from i in Enumerable.Range(1, 5) select new { N = i, NSquared = i * i };
+DataTable dt = DataTable.New.FromEnumerable(x);
+dt.SaveToStream(Console.Out); // write back out as a CSV
+```
> **Also includes support for reading an excel file (.xlsx)**:
-
- var dt = DataTable.New.ReadExcel(@"c:\temp\foo.xlsx");
- var names = from row in dt.Rows where int.Parse(row["age"]) > 10 select row["Name"];
-
+```cs
+var dt = DataTable.New.ReadExcel(@"c:\temp\foo.xlsx");
+var names = from row in dt.Rows where int.Parse(row["age"]) > 10 select row["Name"];
+```
[See here](http://blogs.msdn.com/b/jmstall/archive/2012/04/24/excel-on-azure.aspx) for more about reading excel.