Monday, 27 February 2012

Regular Expression in LINQ

string[] companies = { "microsoft", "IBM", "oracle", "google", "apple", "facebook", "RIM" };
//wildcard search to "%o%o%"
Regex regex = new Regex("oo");
var oo = companies.Where(c => Regex.IsMatch(c, "o.*o")).Select(c => c);
var oo1 = from c in companies
		  where (Regex.IsMatch(c, "o.*o"))
		  select c;

Here we are searching for company names containing two “o”, need not be consecutive.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

C# Reactive Extensions - Buffer and Window

I was going through Buffer and Window in RX, thought a few examples would help clear the differences. First create a buffer of even numbe...