How to check if certain values are not found in specific column?

Hi everyone! I looked around for this topic and couldn’t find anything applicable. I wanted to check a datatable and quickly see if values other than the ones below are found in a specific column, and return a boolean. I tried doing a for each row but it doesn’t seem to be the very efficient. Please let me know if there might be another solution.

Here is the criteria:

  • does not start with “11”
  • does not start with “22”
  • does not start with “33”
  • does not equal variable1

True: a value other than those 4 is found in the column
False: no other value (other than those 4) is found in the column

I tried this in an IF condition, but it’s not allowing me to add additional conditions:
dt.AsEnumerable().Any(Function(x) Not x(“Column-1”).ToString.StartsWith(“11”))

@sidb

Try as below

use If and write Datatable.Rows.Count > 0

Then->False
Else->True

Thanks

1 Like

Hi,

Can you try the following expression?

dt.AsEnumerable().Any(Function(x) Not (System.TExt.RegularExpressions.Regex.IsMatch(x("Column-1").ToString,"^(11|22|33)") OrElse x("Column-1").ToString=variable1))

Regards,

1 Like

give a try on following

Assign Activity
LHS: CheckResult
RHS

(From d in dt.AsEnumerable
Let c1 = Not {"11","22","33"}.Any(Function (c1) d("Column-1").toString.Trim.StartsWith(c1))
Let c2 = Not d("Column-1").toString.Trim.Equals(variable1)
Let res = {c1,c2}.All(Function (r1) r1)
Select fc = res).Any(Function (x) x)

Feel free to adopt / finetune it by using All / Any on the particular checks

1 Like

‘IsMatch’ is not the same as ‘StartsWith’ correct? If so, I don’t think this would be accurate.

Hi,

Use multiple filters in the linq like below.

YourDT.AsEnumerable.Where(Function (x) Not x(“ID”).ToString.StartsWith(“11”) AND Not x(“ID”).ToString.StartsWith(“22”) ).CopyToDataTable

1 Like

Hi,

IsMacth returns true or false which is evaluated string with regex pattern. In this case, "^(11|22|33)" means StartsWith 11 or 22 or 33.

Hope this helps you

Regards,

1 Like

Yes this definitely helps! Thank you!! Do you mind clarifying one more thing? Does the expression you provided return a TRUE if there is just one row which does not start with 11, 22, etc.?

This is what I was trying to do initially but it seems I just had a syntax error. Thank you!

For me i am able to filter it my end. not sure what is the syntax you are getting. Please follow the multiple suggestions from our forum members and see which one fit better follow that. if you want you could review the attached the sample process i have created. thanks.

LinqDemo22.zip (9.0 KB)

Hi,

Does the expression you provided return a TRUE if there is just one row which does not start with 11, 22, etc.?

Yes, as the following.

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