Culture sensitive string.Contains()

This will provide an Extension Method to enable you to perform a safer contains search within a string.

For projects built on framework v2.0, make sure you include:

namespace System.Runtime.CompilerServices
{
  [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class
  | AttributeTargets.Method)]
  public sealed class ExtensionAttribute : Attribute
  {
    public ExtensionAttribute() { }
  }
}

Here’s the method:

public static bool Contains(this string searchWithin, 
string value, StringComparison comparisonOptions)
{
    if (value.Length == 0)
    {
        return true;
    }
    for (int i = 0; i < (searchWithin.Length - value.Length); i++)
    {
        if (searchWithin.Substring(i, value.Length).Equals(value, comparisonOptions))
        {
            return true;
        }
    }
    return false;
}
something.Contains(somethingElse, StringComparison.CurrentCultureIgnoreCase);

See here http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/ebc4258ed2c4270f/c48b6c15df01e8bf?pli=1 for more information on the issue.

Following

  • funniest10k
  • the-absolute-funniest-posts
  • mikelernerphotography
  • attentionindustry
  • tastefullyoffensive
  • evangotlib
  • infoneer-pulse
  • merlin
  • poplipps
  • cavalier
  • redshooter
  • frezned
  • amyvernon
  • minimalistco
  • theclearlydope
  • deviantart
  • yagottabelieve
  • mashable
  • poptech
  • gregbabula
  • john
  • teaim
  • despicablealexis
  • purple-lightsaber
  • toptumbles
  • hellonewyork
  • nonprofit-design
  • plus5mace
  • wantful
  • pixel2html
  • adobegripes
  • kimjongillookingatthings
  • tuneage
  • mikehudack
  • sirmitchell
  • officialbeastieboys
  • wondertonic
  • jordanwaller
  • badassjs
  • iiiil0liiii
  • fuzzythinking
  • manxmidge
  • rosskempfolds
  • londonelek
  • bigpinots
  • hoveringartdirectors