As far as I know it’s not possible to use regex in Select. It’s also not easy/possible to use Linq in UiPath, which would be probably the best choice using C#.
In UiPath I would probably iterate with for each and check each row with “Is Match” activity.
If you would like to remove all the row matching the logic you asked for previously you would just need to revert the boolean inside the Linq lambde expression like this.
Note that here it is copied to a second datatable but it is perfectly fine to assign it to “dt”, which will overwrite the previous one, in case you would not need it.
Last example which was not mention yet, if you want a real One liner, you can also inline the regex, but it is not that pretty if you have a big datatable because it will instance the Regex for each iteration.
Anyway, assuming that you have thousand rows, we are talking about max few milliseconds
dt.AsEnumerable().Where(Function(x) (x(“Company”).toString = “5311” Or x(“Company”).toString = “5301”) AndAlso New System.Text.RegularExpressions.Regex(“\b[0-9]{2}\b”).IsMatch(x(“CustId”).ToString) = False).CopyToDataTable
Thanks for the suggestion. Thanks for being so patient in answering all my queries. learnt a lot of new things.
Also I have one last query for future reference:
In this query I will get all the values that are true for the condition, if I want to remove the rows selected in the current query from my datatable what can be the process.
Also is their any link where i can explore lambda exp and linq learn a few other tricks.
Regarding Lambas documentation and links, i don’t have anything specific, it is considered as an advanced topic of .Net and require a lot of practice. In addition, they are difficult to be understood by a lot of people, specially in the RPA World.
I would simply make google search with the keywords (“Linq”,“VB.Net”,“Lambda expressions”).
For Selecting extact oposite of the previous lamba you need to add this.
Assign dbBaseFile = dbBaseFile.AsEnumerable().Where(Function(x) ((x(“Company”).toString = “5311” Or x(“Company”).toString = “5301”) AndAlso New System.Text.RegularExpressions.Regex(“\b[0-9]{2}\b”).IsMatch(x(“CustId”).ToString) = False)=False).CopyToDataTable
If it is not resolving your case you can still attach a workflow and give example of how your initial and filtered DT would look like.
You would also have .RemoveAll available List(of DataRow) but it would not be in one line anymore :
You need to :
Create a List of Datarow out of your datatable (Assign dataRowList = dt.Select().ToList)
create an integer variable which will return the rows removed.
Assign intRemovedCount = dataRowList.RemoveAll(Function(x) (x(“Company”).toString = “5311” Or x(“Company”).toString = “5301”) AndAlso New System.Text.RegularExpressions.Regex(“\b[0-9]{2}\b”).IsMatch(x(“CustId”).ToString) = False)