Search code examples
c#windows-phone-7

String.Contains() with ignoring case and culture


I had found only StringComparison, but that's not working for Contains. Another necessary thing is ignoring case, and "ä" should equials to "a".


Solution

  • public static bool CustomContains(this string source, string toCheck)
    {
            CompareInfo ci = new CultureInfo("en-US").CompareInfo;
            CompareOptions co = CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace;
            return ci.IndexOf(source, toCheck, co) != -1;
    }