Linq query to remove a particular string from a particular column

Hi All

Kindly help as am not good with Linq query. I have a column example as below

Column name -session Id, it has data as below
#ADA#Abcd12345
#ADA#abcd3456

Now I need to remove this particular string #ADA# from all the rows of this column n then need to copy to data table the entire data table.

Could you pls advise Linq query?

Thanks for your help

Regards
Taruna

Hi Taruna,

Try out this

  1. Read the data from the source file into a data table using the Read Range activity.
  2. Use the Select method with LINQ to remove the #ADA# string from all the rows of the session Id column. Here’s an example LINQ query:

dataTable.AsEnumerable().Select(Function(row) row.Field(Of String)(“session Id”).Replace(“#ADA#”, “”)).CopyToDataTable()

This LINQ query will select all the rows in the data table, remove the #ADA# string from the session Id column of each row using the Replace method, and return the result as a new data table using the CopyToDataTable method.

newDataTable = dataTable.AsEnumerable().Select(Function(row) row.Field(Of String)(“session Id”).Replace(“#ADA#”, “”)).CopyToDataTable()

This expression will assign the result of the LINQ query to the newDataTable variable.

1 Like

Hi Kiran,

its showing error. could you pls advise.


Thanks
Taruna

Hi @taruna.mehra

Give a try with the following

In the invoke code use this

dtInput.AsEnumerable().ToList().ForEach(Sub(r) r("Column name -session Id")= r("Column name -session Id").ToString().Trim().Replace("#ADA#", String.Empty))

Make sure to replace the exact column name within the double quotes

Regards!

1 Like

Its sorted with For each data row but if i will have 200000 rows, it will take lot of time.

1 Like

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