c# - LINQ Filtered List using Exact Word -


I have this list of strings; I only want to filter those items that would match exact for my searched keyword. Are there. For example, I have the keyword "in", I want to filter the result only for those items that contain the word "in". help please.

Code

  Fixed IEnumerable & lt; String & gt; GetData () {var strList = new list & lt; String & gt; {"I am in love", "coffee is caffeine", "best inn so far", "inside", "in the dark"}; Var filteredItems = strList.Where (x => x.Contains ("in")); Return filtered item; }   

From my list, I want to return item 1 and item 5 as they are the items that have the exact word "in".

Https://i.stack.imgur.com/lp7WV.png "alt =" Enter image details here ">

There is a way to do this:

  var filteredItems = strList.Where (x => ("+ +" + "").   

Or it:

  var filteredItems = strList.Where (x => Regex.IsMatch (x, "(^ |) In ($ |) ")); Case insensitive version:  
  var filteredItems = strList.Where (x => (" + x. ToLower () + "") ("In")); Var filteredItems = strList.Where (x => Regex.IsMatch (x, "(^ | \ s) in ($ | \ s)", RegexOptions.IgnoreCase);    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -