I have a data table (dt1) and in the “Email” column I need to remove rows that are null or whitespace for that field. I tried using filters for contains, etc and I am getting mixed results. I know I can achieve this with regex and I was hoping someone could help. Thanks!
Try this
Outputdatatable=Datatablevaraible.AsEnumerable.where(function(r) r(“Email).tostring<>”").CopyToDataTable
Cheers
Use an “Assign” activity to create a new data table that contains only the rows you want to keep. Let’s call this new data table filteredDt.
In the “Value” field of the “Assign” activity, use LINQ to filter the rows of dt1 based on the condition that the “Email” column is not null or whitespace. You can use the Where method with a lambda expression to achieve this. Here’s the code for the “Value” field:
filteredDt = dt1.AsEnumerable().Where(Function(row) Not String.IsNullOrWhiteSpace(row(“Email”).ToString.Trim)).CopyToDataTable()
Hi
There is a knowledge base in UiPath forum on all functionalities of datatable
Have a view on this for more insights
For your scenario
This is with normal IsNullOrEmpty method
dt1 = dt1.AsEnumerable().Where(Function(a) NOT String.IsNullOrEmpty(a(“Email”).ToString.Trim) ).CopyToDatatable()
If you want to remove with the Regex
dt1 = dt1.AsEnumerable().Where(Function(a) NOT System.Text.RegularExpressions.Regex.IsMatch(a(“Email”).ToString.Trim, “[\W|\w]").CopyToDatatable()
Hope this helps
Cheers @chrystine.h
It works like a dream, thanks so much!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.