I have a list of strings which contain 4 items:
Orange
Lemon
Pepper
Tomato
Also, I have a String str which has a sentence:
Today, I ate a tomato and an orange.
1) How can I check that str has some keywords from list? without considering upper or lower case letters, basically capturing anything that matches?
I tried this but it doesn’t work because it will look for the same words. list.Contains(str)
Also Dim result As String() = list.FindAll(str, Function(s) s.ToLower().Contains(str)) but also didn’t work.
2) What if the word tomato was tomatoes in str, how can I still detect the tomato part and discard the es part?
Any suggestions or ideas ?
With LINQ and Regular Expressions you can check if string contains any keyword:
Or get matched keywords:
BTW this will match both
tomatoesandfootomato. If you need to match start of word, then search pattern should be changed a little:@"(^|\s)" + keyword