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;
oo1.Write();


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

Comments

Popular posts from this blog

Wix: How to hide the License Agreement dialog in Mondo UI

WPF: TreeView example (Part 4)