Hi.
i want to find all * characters in a string and showing them red in a richtextbox. How can i do that?
string str = "asd***asd***dfg***wer**";
in a richtextbox;
asd***asd***dfg***wer**
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Kirtan PatelRank #292 · 8.6K reputationPosted Jan 11, 2010, 10:53 AM EST
see screen shot :)
take a look at my project files ..if you made any mistake in code then correct it by looking at code.
and let me know if any problem arise :)
and if it helps you then check "do you like this answer" check box please :)
Kirtan PatelRank #292 · 8.6K reputationPosted Jan 11, 2010, 10:05 AM EST
if my answer helps you then please check "do you like this answer" check box please :) it helps me .
Code
----------------------
using System.Text.RegularExpressions;
private void button1_Click(object sender, EventArgs e)
{
Regex rex = new Regex("[*]*");
foreach(Match m in rex.Matches(richTextBox1.Text))
{
// Preserve Position of Cursor
int pos = richTextBox1.SelectionStart;
richTextBox1.Select(m.Index, m.Value.Length);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectionStart = pos;
richTextBox1.SelectionColor = Color.Black;
}
}
if you want to change Color in realTime when user types the Text then Just Place the code in TextChanged Event instead of Button Click :)
yokzuRank #5,421 · 300 reputationPosted Jan 11, 2010, 10:19 AM EST
Your codes didnt worked for me and I really dont know why. Is your code working on second or third lines? My string is like below;
3.note
11.01.2010 21:27:13
***********************
2.note
11.01.2010 21:27:03
***********************
1. note
11.01.2010 21:26:52
***********************
yokzuRank #5,421 · 300 reputationPosted Jan 11, 2010, 6:29 PM EST