|
-
Nov 9th, 2012, 05:41 PM
#1
Thread Starter
Hyperactive Member
Searching value containing any string (or part of) in a string array
I will have a search string but need to search by each individual string in it, so I'm creating an array:
string[] criteria = param.sSearch.Split(' ');
Now the first issue is that say "Jack ", will give you two items, the latter be a space.
Then I search on a collection of say "Person" objects, where I overriden the "ToString" method to give you someting like "FirstName LastName EmailAddress Employer Andsoon"
I want to return all items in the collection where any string in the criteria array match (even partly) any value in the object's .tostring value.
not sure if it make sense, but for what it matter the following does not work as I hope:
Code:
IList<CompanyMember> allMembers = CurrentCompany.Members.ToList();
IEnumerable<CompanyMember> filteredMembers = allMembers;
if (!string.IsNullOrEmpty(param.sSearch))
{
string[] criteria = param.sSearch.Split(' ');
filteredMembers = from xin allMembers
where criteria.All(val => x.ToString().Contains(val))
select x;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|