Like query ing LINQ to Object

末鹿安然 提交于 2019-12-04 16:06:52

Something like:

var matches = states.Where(state => state.Contains(searchText));

That's fine if the case matches as well, but it doesn't work so well for case-insensitive matches. For that, you might want something like:

var matches = states.Where(state => 
      state.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) != -1);

Choose the exact string comparison you want appropriately - you might want to use the current culture, for example.

Also check

  StartsWith
   EndsWith

another alternate

 var query = from c in ctx.Customers
                where SqlMethods.Like(c.City, "L_n%")
                select c;

If you want a really sophisticated approximate match check out Levenshtein distance in http://code.google.com/p/google-diff-match-patch/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!