I am looking for ways to find matching patterns in lists or arrays of strings, specifically in .NET, but algorithms or logic from other languages would be helpful.
Say I have 3 arrays (or in this specific case List(Of String))
Array1 'Do' 'Re' 'Mi' 'Fa' 'So' 'La' 'Ti' Array2 'Mi' 'Fa' 'Jim' 'Bob' 'So' Array3 'Jim' 'Bob' 'So' 'La' 'Ti'
I want to report on the occurrences of the matches of
('Mi', 'Fa') In Arrays (1,2) ('So') In Arrays (1,2,3) ('Jim', 'Bob', 'So') in Arrays (2,3) ('So', 'La', 'Ti') in Arrays (1, 3)
…and any others.
I am using this to troubleshoot an issue, not to make a commercial product of it specifically, and would rather not do it by hand (there are 110 lists of about 100-200 items).
Are there any algorithms, existing code, or ideas that will help me accomplish finding the results described?
As others have mentioned the function you want is Intersect. If you are using .NET 3.0 consider using LINQ’s Intersect function.
See the following post for more information
Consider using LinqPAD to experiment.
http://www.linqpad.net