How to check if any word in my List contains in text

后端 未结 4 866
抹茶落季
抹茶落季 2020-12-16 12:39

I have a

List words = new List {\"word1\", \"word2\", \"word3\"};

And i want to check using linq if my string

4条回答
  •  难免孤独
    2020-12-16 13:27

    For your first condition

    List words = new List { "word1", "word2", "word3" };
    string test = "word1";
    bool isFound = words.Contains(test);
    

    For your second condition

    bool isFound = sentences.Any(x => x.Split(new char[] { ' ' }).Contains(test));
    

    As an unrelated side-note

    You are changing the question's scope after getting some answers and that is not a good way to ask questions. :)

提交回复
热议问题