Editing a Single Column using LINQ

I have a datatable which looks like this:


Id like to remove all the special characters other than digits from the Phone No. column. I know this can be achieved using a For Each, but I wanted to know whether it was possible using LINQ.


The columns are dynamic i.e, we might not always know what all columns might be added, as I am joining several tables together.

Help would be most appreciated, thanks in advance!

Kind Regards,
Ashwin A.K

Just use a For Each. This obsession around here with avoiding For Each is pointless. It’s not a performance issue. LINQ loops anyway, it’s just hidden to you.

1 Like

in case of only a few columns are to update go for a for each
we can do it with a regex.replace(YourString, "\D", "")

In case of the column name / index is unclear we can iterate over the ItemArray and check if its needed (also can exclude columns within the same time)

Doing it consequently on all columns:

Also have a look here:
How to Update Data Column Values of a Data Table | Community Blog

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