1

I have a string like this:

var str = "DAVID CORPORATION"

then i have a list of substrings that i dont want in the str.

var describers = new List<string> {"CORP", "INC", "LTD", "TECH", "ENGINEER", "LLC","MICROELE"};

then i split the str here into a list:

var strList = str.Split(' ').ToList();

now i want to remove all items of that list that contains the substrings in describers. I found this way to do it a million times all over the internet.

strList.RemoveAll(x => describers.Contains(x));

This does not work because all it does is check if the describers contain the whole word of the strList. I need it to work in reverse.

This doesn't work but its an algorithm of how i want it to work.

strList.RemoveAll(x => x.Contains(describers.Any()));

Cannot convert from 'bool' to 'string'

of course, but how to i remove the item in strList that contains the substring item from describers.

..and only in a linq.lamba. I am trying to stay away foreach/for/do loops.

1 Answer 1

7

You can do the following using Any:

strList.RemoveAll(x => describers.Any(d => x.Contains(d)));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.