I wonder what is my best option to parse CSV into a DataTable.
My CSV is in this format
Separator: comma
Delimiter: double quotes (e.g."string")
Escape: 2x double quotes
Here is the example:
Col1,Col2,Col3,Col4 1234,active,"This is a long text with new lines, commas and all", XGF232 1235,active,"This is also a ""long"" text with new lines and all", XHD233
- The problem is that numbers or short; one word strings are not enclosed within quotes.
- The other problem is that long strings which are enclosed within quotes that also have a "string" nested are escaped with ""string"".
PS: Excel understands this format without an issue.
EDIT:
The comments pointed me at a different options. I searched the libraries available and I found LumenWorks.Framework.IO.Csv which seems to do the job just perfect.
Using csv As CsvReader = New CsvReader(New StreamReader(filename), True)
Dim fieldCount = csv.FieldCount
Dim headers() As String = csv.GetFieldHeaders()
dt.Load(csv)
End Using