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");
//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");
No comments:
Post a Comment