Answer the question
In order to leave comments, you need to log in
How to check if a string contains a word from an array?
Hello! Can you please tell me how can I check a string for the presence of words from a certain array? I need the most optimal option)
I tried to use the String.Contains method, but (if I understand correctly) only one word can be checked there:
if (message.Contains("Хай")) //Срабатывает отлично)
Answer the question
In order to leave comments, you need to log in
You can use LINQ.
var foo = stringArray.Any(str => message.Contains(str));
Going through the elements of the array with words (the for loop), check each of them for content in the string.
Although they joke about 1C programmers, but for NLS
the program looks exactly like this
add word A
to the list add word B to the list
As long as there are values \u200b\u200bin the list, assign this value to the variable
Everything that is inside is repeated
if the array contains a string from the assigned value, then we do something
End of repetition Everything inside repeats
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question