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

后端 未结 4 843
抹茶落季
抹茶落季 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:36

    While most of the solutions presented are functional (the all call Contains, which will give you the desired solution), if the list and the text are large, you may have performance issues.

    From the problem that was stated, I'd think that you call a word anything between spaces or any other divisor. So, I'd recommend you split your myText into a list of words, and compare each one of them to you list of words, now using contains.

    It's way more complex, of course; You'd have to make sure split words correctly -- but with larger strings (for example, a text file) there might be some performance gain.

提交回复
热议问题