Reputation: 2005
I have a list of strings and if one element is a substring of another element, I want to remove that shorter element.
So,
{abc, def, ghi, ab, cd, ef} => {abc, def, ghi, cd}
I tried:
list = list.Where((x, y) => x.Item1 != y.Item1 && x.Item1.Contains(y.Item1) == false);
but somehow y
is an integer.
Upvotes: 1
Views: 577
Reputation: 726479
The overload of Where
that you used is for filtering with an element and the index. You need to use the "regular" Where
, like this:
var res = list.Where(x => !list.Any(y => x != y && y.Contains(x)));
Upvotes: 1