First format all the text in the selected color, then find "stackoverflow" and format it in the normal format. This way, you donβt have to bother with the problem of finding something, but formatting something else.
For technical details, I need to know what control you use to display text (text box, Rtf, Html).
static void Main(string[] args) { string strComplete = "stackoverflow is good, I mean, stackoverflow is really good"; string strSearch = "stackoverflow"; Console.WriteLine(FormatString(strComplete, strSearch)); Console.ReadKey(); } private static string FormatString(string strComplete, string strSearch) { string strSpannedSearch = string.Format("{0}{1}{2}", "", strSearch, ""); return strComplete.Replace(strSearch, strSpannedSearch); }
static void Main(string[] args) { string strComplete = "stackoverflow is good, I mean, stackoverflow is really good"; string strSearch = "stackoverflow"; Console.WriteLine(FormatString(strComplete, strSearch)); Console.ReadKey(); } private static string FormatString(string strComplete, string strSearch) { string strSpannedSearch = string.Format("{0}{1}{2}", "", strSearch, ""); return strComplete.Replace(strSearch, strSpannedSearch); }
source share