Selectively coloring text in RichTextBox

后端 未结 4 1805
深忆病人
深忆病人 2020-11-28 14:50

How can I paint in red every time I meet the letter \"A\" in RichTextBox?

4条回答
  •  难免孤独
    2020-11-28 15:22

    This is the C# code for EJ Brennan's answer:

    public string Highlight(object Search_Str, string InputTxt, string StartTag, string EndTag) 
    {
        return Regex.Replace(InputTxt, "(" + Regex.Escape(Search_Str) + ")", StartTag + "$1" + EndTag, RegexOptions.IgnoreCase);
    }
    

提交回复
热议问题