tags:

views:

46

answers:

2

I need to search a name which is stored in collection.

Search criteria: eg: 'Search Name' . If i give 'N' this name should be displayed. If i give any alphabet then all the names which contains the given alphabet should be displayed..the name can contains more than one word.

I am using List collection.

search criteria: eg. 1) a 2) xyz 3) full name 4) Name should display if it contains the given alphabet at any position.

I have .Net 3.5

+5  A: 

You can use linq as so

    List<MyObject> results = searchList.Where(x => x.SearchName != null 
         && x.SearchName.Contains(searchString)).ToList();
Russell Steen
+2  A: 

Basically, you can combine Linq and Regex:

List<string> myList;
List<string> search(string pattern)
{
   Regex regPattern = new Regex(pattern);
   return myList.Where(s => regPattern.IsMatch(s)).ToList();
}
PierrOz