lukik lukik - 7 months ago 60 Question

Extract whole row/line using Lumenworks CSV Parser

How do I read the whole row while using

CVS parser? So far am only able to read entry by entry but not the whole row. i.e. if a row is
, am able to pluck out each individual alphabet. However, I want to be able to read the whole row

Currently I have:

my_csv = New CsvReader(New StreamReader(file_path), False, ",", resetPoint)
field_count = my_csv.FieldCount
While my_csv.ReadNextRecord()
'process the data here
'This code will process each individual alphabet in one row

The above reads each individual alphabet. What I want is to have something like

row = my_csv.row

Is this option available or something similar?


When you have basic VB programming skills like me, this is what you come up with to solve the problem

Dim my_string As String = ""
For x As Integer = 0 To my_csv.FieldCount - 1
my_string += my_csv(x).ToString.Trim + ","
my_string = Mid(my_string, 1, Len(my_string) - 1)
Return my_string

By all means use the code in the marked answer. Its super elegant!


I haven't found anything available, but this should work:


Dim rowFields = Enumerable.Range(0, my_csv.FieldCount).
   Select(Function(field) my_csv(CInt(my_csv.CurrentRecordIndex), field))
Dim line As String = String.Join(my_csv.Delimiter.ToString(), rowFields)


var rowFields = Enumerable.Range(0, my_csv.FieldCount)
    .Select(field => my_csv[(int)my_csv.CurrentRecordIndex, field]);
string line = string.Join(my_csv.Delimiter.ToString(), rowFields);