Linq to Convert String List in a DataTable

Hello
I know probably its something that I can do with a split a foreach activities but i would like to know if is possible do it in Linq.

My input is a string, is the following:
“Column1,Column2,Column3,Column4,Column5,Column6,Column7,2022-03-01,357159,741852963,33.12,PLAYSTOE,$1.00,table”
And my outputthe idea should be a DataTable looks like this:

The string no always contains only 7 columns, could coldatins more or less so the idea its should be dinamic, its mean indicating the number of columns.

We would assume that it is CSV Data and the string also contains the Linebreaks between the rows.

So it is recommended to use the appropriate CSV Options (Read CSV, generate DataTable) for this use case.

When custom parsing is needed, then lets first identify the exact needs for it

The string does not contain the line breaks, it only contains that string, I understand that the string can be converted into a list.
But I want to know if it is possible, I don’t need to convert it to CSV.
The question would be, is it possible to use that String that does not have line breaks indicated to convert it into DT?

My exact need is to convert that String into a DataTable, I don’t need to write it in an excel or a CSV, I need to convert it into a DataTable.

When a LINQ Approach is focussed e.g. for learning purpose we have to consider the following main parts:

  • datatable preperation
  • datatable population

And for this we would rely on some constraints eg. first part Header Detection, and general split on comma

Have a look at

And

the First Operator which we can think about to setup a LINQ oriented solution

For LINQ in general have a look here:
[HowTo] LINQ (VB.Net) Learning Catalogue - Help / Something Else - UiPath Community Forum

At this statement we could also state:

  • CSV Data Parsing into a datatable e.g. with generate Datatable has nothing to do with writing Data to Excel

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.