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 From my list, I want to return item 1 and item 5 as they are the items that have the exact word "in". There is a way to do this: Or it:
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; }
var filteredItems = strList.Where (x => ("+ +" + "").
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
Post a Comment