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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Jan 11, 2010, 3:53 PM
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 :)
yokzuPosted Jan 11, 2010, 11:29 PM
yokzuPosted Jan 11, 2010, 3:19 PM
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
***********************
Kirtan PatelPosted Jan 11, 2010, 3:05 PM
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 :)