Linq Query To Remove Spaces

Hi

I have datatable with 4 columns.
I have to remove all the spaces from the first column for all the data rows and return the data table.

Can you help me with Linq Query.

Hi @JITU99

Can you share the sample input & desired output data, so that we can analyze your requirements?

Best Regards.

Input

Col1 Col2 Col3 Col4
AA bb c d e f d a asasd asd asd asd asdf
a asrdg jikt hsf wer qwer qwer

Output Datatable

Col1 Col2 Col3 Col4
AAbbcdefdaasasdasd asd asd asdf
aasrdgjikthsf wer qwer qwer
1 Like

@JITU99

Please try this query in the Invoke Code activity:

io_dt.AsEnumerable.ToList.ForEach(Sub(row)
row("Col1") = row("Col1").ToString.Replace(" ","")
End Sub)

Invoke Code Arguments Panel:

Edit: Output be like-

image

Hope this helps,
Best Regards.

we would recommend using a for each
How to Update Data Column Values of a Data Table | Community Blog

The LINQ way could be used e.g. with DataTable reconstruction approach

Assign Activity:
dtCleansed = YourDataTableVar.Clone

Assign Activity:
dtCleansed =

(From d in YourDataTableVar.AsEnumerable()
Let c1 = d(0).toString.Trim.Replace(" ", "")
Let ra = d.ItemArray.Skip(1).Prepend(c1).toArray
Select r = dtCleansed.Rows.Add(ra)).CopyToDataTable
1 Like

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