Split cell values in datatable using linq

Hi Everyone,

My requirement i have a huge excel with many rows

eg : Input datatable

Output required

basically i need to get the first of the value under name column
can u suggest me some solutions in linq

Thanks in advance

lets assume the first part is always a digit

  • option 1: regex for extraction
  • option 2: String split method on space

In general it is still a case for updating the collumn value within a for each row

For demp purpose a LINQ could look like this (datacol structure is important for the solution details)

Columns: Name, Value, origin datatable: dtData

Assign Activity:
dtResult = dtData.Clone

Assign Activity:
dtResult =

(From d in dtData.AsEnumerable
let spl = System.Text.RegularExpressions.Regex.Match(d("Name").toString, "\d+").Value
Let ra = d.ItemArray.Skip(1).Prepend(spl).toArray
Select r = dtResult.Rows.Add(ra)).CopyToDataTable

an alternate for let ra
Let ra = new Object(){spl, d(1)}

1 Like

@ppr thanku it worked

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