>>>My point was that in C# since there is no way to do a case insensitive search you have to do in effect three searches (yes, I realize there would be other possible combinations of upper and lower but these are in fact the three most likely )
>>
>>There is actually. But you'll need to write a method that uses String.IndexOf() in a loop
http://msdn.microsoft.com/en-us/library/ms224424.aspx>>You can pass an offset where the search starts in the string and StringComparison
>>
>
>Sorry, I'm being a little thick. I'm looking at the link and I see how IndexOf finds the first occurrence of a string but beyond that I'm not getting how it finds a string wtihout regard to case?? and even moreso, how it counts the number of occurrences in that larger string ?
>
>Could you point to and example of the kind of method you are talking about ?
>
>TIA
>
Charles,
The link should point to : String..::.IndexOf Method (String, Int32, StringComparison)
I haven't got vs2010 installed at the moment so forgive me the syntax errors - and bugs - cannot test
// I suppose IndexOf() returns the index in the string, ie not relative to where the search started
void Replace2(StringBuilder sb, string searchFor, string replaceBy)
{
string s = sb.ToString();
int offset = 0;
int delta = 0;
while ( offset < s.Length )
{
if( (offset = s.IndexOf(searchFor, offset, StringComparison.OrdinalIgnoreCase) < 0 )
break;
sb.Remove(offset + delta, searchFor.length) ;
sb.Insert(offset + delta, replaceBy);
offset += searchFor.Length ;
delta += replaceBy.Length - searchFor.Length ;
}
}
Gregory