How to convert a string variable to a data table

Could someone help me convert a string variable to a data table? thank you so much Appreciate your help

please share sample string and expected output sample. Thanks

When string is about CSV have a look at

  • Read CSV
  • Generate DataTable
1 Like

Hi @Daniel_Hernandez1

→ Read Text File
Output-> str_Text (DataType:System.String)
→ Generate DataTable from text
Output-> dt (DataType: System.Data.DataTable)

Regards

1 Like

Hey @Daniel_Hernandez1

  1. Build DataTable

  2. Split string into rows
    rows = inputString.Split(Environment.NewLine.ToArray(), StringSplitOptions.RemoveEmptyEntries)

  3. For Each row in rows
    Split each row into columns
    columns = row.Split(‘,’.ToArray(), StringSplitOptions.None)

  4. Add Data Row to DataTable
    ArrayRow: columns
    DataTable: outputDataTable

1 Like