If I have 2 lists of strings:
List<string> firstList = new List<string>("010", "111", "123");
List<string> secondList = new List<string>("010", "111", "999");
How can I compare each individual character in each item from the lists? Ex: Should compare “0” with “0”, “1” with “1”, “0” with “0” and so on. It appears that I can use SelectMany but I am stuck on how to do it
EDIT:
These lists should return true when compared with each other (as asterisk means any character and I am validating to ensure that each item is exactly 3 chars in length)
List<string> firstList = new List<string>("010", "111", "123");
List<string> secondList = new List<string>("010", "1*1", "***");
If you just want to compare for a matching character sequence between your lists:
This would result in
true, i.e. for the following two lists – their character sequences match ("010111123"for both), their individual string entries do not:Edit in response to comments:
For a wildcard match you could use
Zip()and compare each character, return true if they match based on wildcard conditions, then just check that each element in the zipped sequence istrue.var isWildCardMatch = firstList.SelectMany(x => x).Zip(secondList.SelectMany( x => x),(a,b) =>
{
if(a==b || a ==’‘ || b == ‘‘)
return true;
return false;
Above approach crossed string entry boundaries, which would cause false matches – here a better approach: