0

Possible Duplicate:
Ignoring accented letters in string comparison

I have a search textbox that searches the given text in all the news from the database. So I have this:

List<NewsTranslation> newsTranslations = GetByLanguage(GlobalBL.CultureLanguage);
return newsTranslations.Where(
            e =>
            e.NewsContent.Contains(searchText) || e.NewsDescription.Contains(searchText) ||
            e.NewsTitle.Contains(searchText)).ToList();

which works fine, but I would need it not to consider case or accents on letters.

Thanks

Community
  • 1
  • 1
bokkie
  • 1,477
  • 4
  • 21
  • 40
  • Now, are you sure you don't want to push that searching to the database instead of to an iteration in C#? If you have a lot of news performance would take a pretty big hit – Pablo Romeo Dec 08 '12 at 19:31

1 Answers1

1

This comparator:

string.Compare(searchText, e, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase));

will do the trick. You can include this in your LINQ query where it will of course return 0 when the two arguments are equivalent.

Levi Botelho
  • 24,626
  • 5
  • 61
  • 96