I would like to check for the occurrence of a collection of words in email body/subject or a word document.
I am able to use .Contains, but it only accepts only one parameter. how can use something like this:
s.Contains(“a”, “b”, “c”);
You can use this syntax: s.Contains(“a”) and s.Contains(“b”) and s.Contains(“c”).
The problem is I have a long list. Some 40 words. Is there any other effecient way to do this?
you can create one array string
True/1->value present in the given string
False/0->value not present in the given string
Split the string based on Space and store it in a List of strings. let us take List A
and Define List B with words which you want to compare.
now take int c=ListA.Intersect(ListB).Count
If int c equal to List B.Count then all the words of list B will be there in string. If int c is zero then string won’t contain any of the words of list B
Use regex matching. If your keywords are stored in an array you can simply do Regex.IsMatch(your email as a string,String.join(“\b|\b”,yourArray)) . This makes sure your words don’t occur in other words and returns a boolean.