Finding items that are contained in two lists as substrings

petko_stankoski

I have two lists:

var files = new List<string> {"ax_11118.txt", "ax_422226.txt", "ax_4346436.txt", "678678678.txt"};
var codes = new List<string> { "1111", "1234", "5555" };

I need to find the items in files which contain this format: "ax_code". The result in this case should be : { "ax_11118.txt" }

I know how to make it with foreach, but I was thinking if there is a cleaner way.

Piotr Wojsa

If you want to check just code then:

files.Where(file => codes.Any(file.Contains));

if ax_code:

files.Where(file => codes.Any(code => file.Contains($"ax_{code}")));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Finding substrings that contain each other in two different lists in Pytyhon

Finding items with exact subitems in two lists using LINQ

Finding matches in two lists

R: fastest way to extract all substrings contained between two substrings

Finding items in lists using the in operator

Finding a string between two substrings in arabic

Finding all the common substrings of given two strings

Finding everything between two substrings using regex

C# / .NET comparing two large lists and finding missing items from both list

finding list items by first letter and store in two different lists and combine into dictionary

Find elegant solution for finding same items that follow each other in two lists

Finding property differences in two lists

Prolog: finding intersection of two lists?

Finding the duplicate of strings in two lists of lists

How to compare two lists to keep matching substrings?

Finding consecutive groupings of items in list of lists in Python

Haskell - combinations of lists and finding the maximum number of items

divide items in ngFor into two lists

Conditionally replacing items with two lists

Comparing count of items in two lists

finding common elements between two lists?

comparing two lists and finding indices of changes

Time limit while finding the duplicates in two lists

Finding intersection of two lists of strings in python

finding item in two lists efficiently Python

Finding elements in two lists within certain range

Comparing two lists and finding indices of changes Dart

Prove a property of finding the same elements in two lists

Finding all possible intersections of two lists