Tuesday, July 19, 2011

Case Insensitive Replace() function

For some reason .Net framework does not have the case insensitive replace method in the String class. I found it can very easily be implemented for String class using Extension Method feature of .Net.

Here's the method:
public static string Replace(this string originalString, string oldValue, string newValue, StringComparison comparisonType)
{
int startIndex = 0;
while (true)
{
startIndex = originalString.IndexOf(oldValue, startIndex, comparisonType);
if (startIndex == -1)
break;

originalString = originalString.Substring(0, startIndex) + newValue + originalString.Substring(startIndex + oldValue.Length);

startIndex += newValue.Length;
}

return originalString;
}


And calling this method seems trivial:
originalString = originalString.Replace(@"ABCD", "abcd", StringComparison.InvariantCultureIgnoreCase);


That's it.

Monday, July 18, 2011

CSS Refresh issue in Firefox

While developing a website in ASP.Net I noticed that my CSS file was not immediately refreshed in Firefox and until I noticed; it caused me to think that the CSS I was trying is not correct. Ctrl+F5; Ctrl+R etc does not work.

I found modifying the entry in config did the trick for me:
network.http.use-cache = false


But I believe it should not be that you have to modify config file for the new CSS to load into the browser. But for now this works.