Check for multiple words in an email body/subject

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”);

Thanks,
Joshi

Hi,

You can use this syntax: s.Contains(“a”) and s.Contains(“b”) and s.Contains(“c”).

Thanks,
Ninett

2 Likes

The problem is I have a long list. Some 40 words. Is there any other effecient way to do this?

Hi @Joshikumarav,

you can create one array string
arrValue={“a”,“b”,“c”,“d”}

arrValue.Contains(YourString).Tostring()
True/1->value present in the given string
False/0->value not present in the given string

Regards,
Arivu :slight_smile:

1 Like

@Joshikumarav

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

Regards,
Mahesh

1 Like

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.