Find String that contains all Strings in a list

Hi all!

I am trying to make an RPA that searches a list of strings based on the string input by the user. Below is an example of what im trying to do.

Names is a list of strings that i want to search through and return a string if there is a match. Input is from the user that would be “.split()” into a list which its elements would be used to perform the search. All searches are performed with the “.ToLower” function.

Names = {{Sam Tan Da Ming}, {Ng Xiao Xiao, Alex}, {Sam Wong Ah Boi}}

Case 1: Input = “Sam Tan”, returned result should be “Sam Tan Da Ming”
Case 2: Input = “Alex Ng”, returned result should be “Ng Xiao Xiao, Alex”
Case 3: Input = “Sam Chan”, returned result should be “No Match”

I am currently having more trouble with case 2.

Hi

How about the following?

string.Join(vbcrlf,listName.Where(Function(s) keyword.ToLower.Split(" "c,StringSplitOptions.RemoveEmptyEntries).All(Function(k) s.ToLower().Split(" "c,StringSplitOptions.RemoveEmptyEntries).Any(Function(s2) s2=k))))

Sample
Sample20241021-2.zip (2.6 KB)

Regards,

1 Like

@Theodore

You can try this in assign

Matchedstring = liststr.FirstOrDefault(function(x) str.ToLower.Split(" "c).All(function(y) x.ToLower.Split(" "c).contains(y)))

Cheers

Hi Yoichi!

Your reply has helped alot! However, after experimenting the line in “Message Box”, i realised that if my input was “Sam”, i would get something like “Sam Tan Da MingSam Wong Ah Boi”. Is there anyway the code can be modified include ", " after every entry? Meaning Input: Sam, Result: Sam Tan Da Ming, Sam Wong Ah Boi.

I made edits after figuring out that adding ", " would be more useful for my use case.

Hi,

Can you try to replace vbcrlf with “,” in the above expression, as the following?

String.Join(",",listName.Where(Function(s) keyword.ToLower.Split(" "c,StringSplitOptions.RemoveEmptyEntries).All(Function(k) s.ToLower().Split(" "c,StringSplitOptions.RemoveEmptyEntries).Any(Function(s2) s2=k))))

Regards,

Yes, this works well! Thank you!

Hi Anil_G! Thanks for your reply but i think Yoichi’s solution fit my use case more!

1 Like

Hello @Theodore

You could iterate the input by splitting on whitespace and then iterate and validate against the names in the list.

For each name.xaml (10.6 KB)

Regards
Soren

1 Like

Hi SorenB, initially i used something akin to this but figured that because “Contains” was used instead of “Equals”, inputting “Ng” in an attempt to generate “Ng Xiao Xiao, Alex” would also generate “Sam Wong Ah Boi” and “Sam Tan Da Ming” due to the “Ng” in “Wong” and “Ming”. I would have used this if my requirements were not of a strict search function.

Thanks for your reply tho! I also admit that your code was way cleaner than mine!

1 Like

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