I have a string array, which has three fields, which are field1, field2, field3.
The length of field1 and field2 are both 1. The length of field3 could be 0 and no limited, usually 0 to 6. What I want to do is when giving field1, field2 and field3 string, find the matched string in arrays. Since the length of field1 and field2 are both 1, they must full matched. But for the field3, as long as it matches one char, it matches.
For example:
array[0]="AB:CDE"
array[1]="BA:D"
array[2]="CA:EFG"
array[3]="DE:ABEFG"
If I was given three fields string: C, A, FG, then it matches array[2]
D, E, B, it matches array[3]
How to use Linq do the search? Considering the array could in any format.
I’m using c#
I don’t know exactly how you want the results, but here is a method that returns an array of patterns that match your three fields:
Edit:
Re-reading your question, I wonder if the pattern
CA:EFGwas insteadCA:EGif that would still match your first three sample fields? You said as long as one character matches in field 3, it should be considered a match.This means that if field 3 is
FG, since the pattern contains aGit should be a match.If this is the functionality you want, replace the above method with this one: