Efficient searching for case insensitive ascii substring
<p>I was actually optimizing Regex transformations of large strings. As some calls to Regex.Replace took significant time I inserted conditional calls - something along the lines</p>

<pre><code>if (str.IndexOf("abc", 0, StringComparison.CurrentCultureIgnoreCase) &gt; 0)
    str1 = Regex.Replace(str, "abc...", string.Empty, RegexOptions.IgnoreCase);
</code></pre>

<p>To my surprise the results were not convincing. Sometimes better, sometimes not. Or even worse. So I measured performance of case insensitive IndexOf (I tried also StringComparison.OrdinalIgnoreCase) and found that it may be slower than Regex.Match, i.e. this test:</p>

<pre><code>if( Regex.Match(str,"abc", RegexOptions.IgnoreCase).Success )...
</code></pre>

<p>Particularly for a large string that did not match (ascii) string "abc" I found that Regex.Match was 4x faster.</p>

<p>Even this procedure is faster than IndexOf:</p>

<pre><code>string s1 = str.ToLower();
if( s1.IndexOf("abc") ) ...
</code></pre>

<p>Anybody knows a better solution? </p>
