List Collection Contains exact string

I have a List Collection and say that i am adding 3 items to them.

list.Add(new ContentDomain() {  Id = "1" , Content = "aaa,bbb,ccc,ddd"});
list.Add(new ContentDomain() {  Id = "2" , Content = "aa,bb,cc,dd"});
list.Add(new ContentDomain() {  Id = "3" , Content = "a,b,c,d"});

Now what i want is to fetch the rows that have just 'a' in the Content attribute.

Like i tried something like

list = list.Where(x => x.Content.ToLower().Contains("a")).ToList();

but that would give me all the three rows.

i want to search in a string for the exact string only.

Answers


list.Where(x => x.ToString().ToLower().Split(',').Where(a => a.Trim() == "a").Any()).ToList();

edit: Changed Count() > 0 to Any() for better performance


Need Your Help

Searching a sub-array inside a 2D array (image recognition)

python arrays search numpy image-recognition

Essentially, I have a numpy image array and I'm trying to find if it contains a 2x2 block of particular RGB pixel values. So, for example, if my (simplified) image array was something like:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.