I've seen this question asked in different ways (check if a list contains a certain string or whether a string contains any given character) but I need something else.
The programme I'm working on is Poker-related and displays list of poker hands in the format [rank][suit], e.g. AhKd5h3c, in multiple DataGridViews.
Right now, I have this rudimentary textbox filter in place which is working fine.
for (int i = 0; i < allFilteredRows.Count; i++)
{
allFilteredRows[i] = new BindingList<CSVModel>(allRows[i].Where
(x => x.Combo.Contains(txtHandFilter.Text)).ToList());
}
allFilteredRows is the data source for my DataGridViews. allRows is the unfiltered list of hands from an SQL database. Combo is an individual poker hand.
That only filters for the exact sequence of characters in the textbox, though. What I want is to filter for each rank and suit individually. So if the user types 'AK', all combos that contain (at least) one ace and one king should be displayed. If the input is 'sss', it should filter for all hands with at least three spades. The order of the characters should not matter ('KA' is equal to 'AK') but every character needs to be included and ranks and suits can be combined, e.g. AKh should filter for all hands with at least one ace and the king of hearts.
This goes beyond my knowledge of LINQ so I'd be grateful for any help.
Enumerable.Allis your friend.Where(r => txtHandFilter.Text.All(cardCh => r.Combo.Contains(cardCh)))5h5properly. See my answer. Also, what should5h5match? What shouldh5h5match?5h5hneeds to match two5hor just one?