Check string in a List<of Strings>

activities

#1

Hi folks,

I am trying to find a string (from a list of strings), if that contains in a string (email body). I feel something is amiss. Couldn’t find what or if the approach is right! Also how would i include ignore case while checking?

My use case: Need to check if any of the strings below is contained in the email

List of strings to check:

{“Unable to upload”,“Upload files failed”,“Upload failed”,“Failed to upload”,
“Missing route document”,“Files not received”,“Files not found”,“File transfer failed”,
“File transfer not received”,“Permit not routed”,“Permit is in unreadable format”,“Did not receive permit”,“Received permit from another company”,“Web defacement”})

Email body:

Dear Tom,

Subject: File transfer failed

A ticket has been logged for this request. Please retain this ticket number for reference purposes."

thanks,
Joshi


#2

Hi @Joshikumarav ,

You can use
list.contains("your value")

Regards, Arivu


#3

Actually, that wouldn’t’ help much, would it? Because i need to check every element of the list with my email body. Can i do it wihout a for loop?


#4

@Joshikumarav

keywords.Any(function(s) email.Contains(s))

This will check all the list items in the email for existance


#5

Hi,

You can try like this,

strList.Contains(chkString, StringComparer.OrdinalIgnoreCase)


#6

Perfect. this works. but how do i ignore the word case? check irrespective of uppercase or lower case.

Thanks
Joshi


#7

try keywords.Any(function(s) email.toLower.Contains(s.toLower))


#8

i think that wouldn’t work. Because what I want is to ignore them as my input may come in any case.


#9

This will convert both your email and the string in list to lowercase. Hence this will work


#10

Perfect. Worked like a charm.