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.
Wednesday Sep 22nd