Check if a variable grabbed from an excel cell with a lot of strings matches with any string from another cell

Hi. What would be the suitable approach to check if a variable matches with any string from another cell. Example:

ListOfItems variable = Bag of Chips Cocktail table Individual Salad Sandwich

ColumnList variable = Service Request Cocktail

So basically I want to check if the ListOfItems variable contains/matches any string inside the ColumnList variable. There could be a lot of values inside the variables so is there a suitable approach to be able to check if the ListOfItems variable matches any string inside the ColumnList variable

I tried using the ColumnList.Contains(ListOfItems) and it didn’t work correctly because I need to be able to return it True if it matches any word between both variables not just the whole thing

Hi,

If your variable are List<String> type, the following helps you.

Condition : ListOfItems.Intersect(ColumnList).Any

Regards,

Hi,

I tried the suggested approach but it kept returning that it matches each time even if the listofitems didn’t have a string that matched anything inside the columnlist variable. Originally these variables were under string variable type also. In your default column above, the strings could be any value or could have a huge number of strings also.

Hi,

Isn’t there empty string in both list?
Can you share specific data, if possible?

We can check which data exists in both using following expression.

newList = ListOfItems.Intersect(ColumnList).ToList

Regards,

Sure thing. Will share a couple of examples (keeping in mind these two variables are under the String variable type) -

ColumnList could contain:

Electronic White Board
Fixed Data Projector
Fixed Projector Screen
Flipchart
HDMI Cable
Offsite Projector Hire
Portable Data Projector
Portable Lectern
Powerboard

ListOfItems could contain:

Powerboard
Flipchart
White Board

So for this example it is a match because in ListOfItems it has a string that uses Powerboard and Flipchart from inside ColumnList

** Another fresh ListOfItems could contain:**

Service
Note Pad
Slideshow

So because none of the strings inside the ListOfItems variable doesn’t match with any string inside the ColumnList it would be a false

Hi,

Can you try the following sample?

Sample20210713-2.zip (2.4 KB)

Regards,

As I wouldn’t know what strings could be inside one variable because it is a different one each time it reads the data from an excel cell where it’s then assigned into a variable like all of the data Powerboard
Flipchart
White Board would be in one cell and then assigned into a variable.

So what you have assigned using New List(Of String)From{“Powerboard”,“Flipchart”,“White Board”}

Instead of putting in the strings examples - I replaced it with a variable with all the data will be read

New List(Of String)From{ListOfItems}
New List(Of String)From{ColumnList}

Somehow it doesn’t seem to do the job right as not recognising anything inside the variables and comparing/matching any word in order to return true/false result if there’s any matches

Hi,

Which type is ListOfItems and ColumnList? It seems String type if the above expression show no error. We can see content of the list at locals panel, if set Breakpoint and run debug. Can you check it?

Regards,

Yes these two variables are a string type. The variable named are just titled and is not a list type

Hi,

Alright. I got your situation. Can you try the following sample. It converts from string to List<String>.

Sample20210713-2v2.zip (2.5 KB)

Regards,

Ah brilliant thanks so much, that works much better however there may be some strings for example if the ListOfItems had a part string whereas in the ColumnList may have a full string labelled so it wouldn’t match when I need it to be. For example in the ListOfItems variable it has Fixed Projector where it matches a partial string in the ColumnList variable despite not having Screen in that string. Is it doable to be able to match partial strings?

ColumnList could contain:

Electronic White Board
Fixed Data Projector
Fixed Projector Screen
Flipchart

ListOfItems could contain:

Fixed Projector
Random Word
Test

I’m looking for the output to be true because Fixed Projector in ListOfItem variable matches where Fixed Projector in theColumnList variable is mentioned

Hi,

How about the following?

Sample20210713-2v3.zip (2.4 KB)

Regards,

That did the job. Thank you for your help, it is appreciated :slight_smile:

1 Like

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