Condition to check and return only the unmatched value

Hi i have a Dt and a arr_String with a list of values

Capture

i used for each item in arr_String

          -> for each row in DT
              -> if    item.ToString.Contains(row("ID).toString)

                       ->   Then    True     Else - False

In the above case i want only the unmatched row which is "ID- 3 " to come in the else case.

How to check the item with all the rows and returns only the unmatched on from the list?
Please help

Hi,

Hope the following helps you.

Or the following expression will also work if one or more rows exist in result.

filteredDt = dt.AsEnumerable.Where(Function(r) not r("List_Var").ToString.Contains(r("ID").toString)).CopyToDataTable

Regards,

Hi @Yoichi ,

Thanks for the suggestion but here lis_var does not belong to the datatable, its separate arr_String which contains a list of values.

I used

->  ->for each item in arr_String
      -> for each row in DT
          -> if    item.ToString.Contains(row("ID).toString)

                   ->   Then    True     Else - False


In the above case i want only the unmatched row which is "ID- 3 " to come in the else case.

Hello @MLT,

You have two variables both are list,
you will have to use two for each,

for each row in dt.rows
for each str in arr_String
if row(“ID”).tostring.contains(str){
bool = True
StrID = Row(“ID”)
exit if
}
Else{
bool = False
}

   if Not bool{
      StrID = Row("ID") 
    }
Else{
do nothing
}

@MLT can you check above condition now?

Cheers,
Pankaj

Hi,

Can you try the following?

in this case, we don’t need outer for each.

Regards,

yes i used two for each loop.

since both the list are not in same order the condition returns false for all other values as well

for ex : ID -1 checks with List var - 5_A, 1_B, 4_C,2_D the condition returns false except 1_B

but i want to get only the unmatched ID - 3. Please help me with the condition

Thank you guys

1 Like

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