Hi
If we have a column with numeric, alphabetical and alphanumeric values, how can we use LINQ to filter out only the numeric values?
I tried something like DT.Select(“ColumnName NOT LIKE”+regex) but it isn’t working.
Hi
If we have a column with numeric, alphabetical and alphanumeric values, how can we use LINQ to filter out only the numeric values?
I tried something like DT.Select(“ColumnName NOT LIKE”+regex) but it isn’t working.
In this case, you might use the .Where in vb.net instead of .Select cause I think it’s more flexible and easier to understand.
Example,
dt.AsEnumerable().Where(Function(row) IsNumeric(row(column).ToString.Trim)).ToArray()
will return an array of DataRows
or
dt.AsEnumerable().Where(Function(row) IsNumeric(row(column).ToString.Trim)).CopyToDataTable()
will convert your filtered table to a dataTable
You can also use a Regex pattern as your condition, but if you just need to know if it’s a number you can use IsNumeric()
Hope this helps. Thanks.
Hi @ClaytonM
Thanks…this works!
Do you happen to know if there’s any online resource to know about such commands? Since I don’t have prior .Net experience I wasn’t aware of commands such as dt.AsEnumerable().Where()
I don’t really know of a good resource, but what I do normally (cause I don’t remember how to do certain things) is search in Google and you’ll find many examples in C# and Vb.net. UiPath uses vb.net mostly but you can adjust the syntax from C# if you know the difference (which is basically vb.net uses “Function(x)” instead of “x =>”).
Prctise1.xlsx (8.4 KB)
LinqY.xaml (7.9 KB)
HI , can anyone tell me how to correct this query to filter the column(“NAME”).
Hi @dennis
I saw the validation error, so I deleted .AsEnumerable() and typed it in again .AsEnumerable, and it removed the error.
The other problem is that xyz is not a DataTable type, so you will get another error until you change the variable to the correct type.
Regards.
hmm, I changed the .AsEnumerable() to .AsEnumerable, and still the error is there
the xyz i changed a system.data.datatable
Did you try deleting “.AsEnumerable” completely, then type “.As”, then select “AsEnumerable” from the list (it should be listed there)?
thanks this fixed the issue