How would I say 'if a subject contains' in terms of code?

Hey, apologies if this is a silly question, I’m new…

I have a configuration excel file which is being looked up against to match an email subject with a company name

So EG: if the email says ‘new enquiry’ the sheet will know to put it to ‘client1’ etc.

So I have my variable of pConfig looking up to the variable of pEmailSubject: pConfig(pEmailSubject).ToString

The issue is that the email subject varies, so it will have ‘new enquiry 12345’ and ‘new enquiry 98554’ for example as the customer ID changes. How would I make it so that it essentially says if it ‘contains’ new enquiry to be looked up against?

I hope this makes sense, please ask for clarity if needed. Appreciate your help!

1 Like

Hi.

Welcome to the community.
Do you want to see if the subject contains the phrase “new enquiry” ?
The obvious answer is to use the CONTAINS method.
Would this post help you?
Check if string contains substring

Thank you.

Example: string eMailSubject is “new enquiry 98554”

check it by
if: eMailSubject.Contains(“new enquiry”) → true/false

1 Like

Check out the official documentation on the string.contains method;

Thanks Giannis, I think the issue here is that it needs to only get the first three words from the subject rather than the whole subject. Is there a way I could do this?

The CONTAINS method can do the job but if you want to isolate the three first words you can use SPLIT:

pConfig = pEmailSubject.Split(" “c)(0).ToString +” “+ pEmailSubject.Split(” “c)(1).ToString +” “+ pEmailSubject.Split(” "c)(2).ToString

And then you can check pConfig using an IF statement.

Thanks for your help!

You can try writing this in Subject field of Get Outlook Mail Message or Get Exchange Mail Message activity

To search single item
“@SQL=urn:schemas:httpmail:subject like ‘%Your text1%’”

Or to search muplitple items
“@SQL=urn:schemas:httpmail:subject like ‘%Your text1%’ or urn:schemas:httpmail:subject like ‘%Your text2%’”

Regards,
Navneet
Happy Automation :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.