Showing posts with label Replace with Ignore Case. Show all posts
Showing posts with label Replace with Ignore Case. Show all posts

Wednesday, February 5, 2014

Replace String with ignore case

I have faced a situation where I need to replace some tag in mail body template with value but tags can be created in any case so while replacing I had to do ignore case. So I created a extension method for string as follows.

//main function
        static public string ReplaceIgnoreCase(this string source, string OldText, string NewText)
        {
            source = Regex.Replace(source, OldText, NewText, RegexOptions.IgnoreCase);
            return source;
        }

//implementation
emailbody = emailbody.ReplaceIgnoreCase("<email>", "abc@ggg.com");