Remove first 2 characters from all values in a column

Is there any one liner code/linq instead of using for each loop, to remove first 2 characters from all values in a column of a datatable, if value is not null?

use invoke code activity and pass in your datatable

dt1.AsEnumerable().ToList().ForEach(Sub(row) row("columnName")= Right(row("columnName").ToString, row("columnName").ToString.Length-2)

hi i got an error where row is not declared

are you usiung invoke code?? upload your xaml here please


dt.AsEnumerable().Where(Function(row) Not row(“columnName”).ToString.Equals(“”)).ToList.ForEach(Sub(row)
row(“columnName”)= Right(row(“columnName”).ToString), row(“columnName”).ToString.Length-2))

you have to pass in your datatable as an argument…

there is one extra closing bracket. Try removing it.

dt1.AsEnumerable().ToList().ForEach(Sub(row) row("columnName")= Right(row("columnName").ToString, row("columnName").ToString.Length-2))

Hi @TyraS

Use the below linq queries to remove the first 2 characters from all values in a column.

dt = dt.AsEnumerable().Where(r = > r["Column1"] != null).Select(r = > new { r["Column1"] = r["Column1"].ToString().Remove(0, 2) }).CopyToDataTable();

Hope it helps!!