thanks.your solution.I am very grateful
I found Regex.It solved my problem.Here's the code:
for(Match match4 = new Regex("if | while |$*").Match(richTextBox1.Text); match4.Success; match4 = match4.NextMatch ())
{
richTextBox1.Select (match4.Index, match4.Value.Length);
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.DeselectAll ();
richTextBox1.SelectionColor = Color.Black;
}
richTextBox1.SelectionStart = richTextBox1.Text.Length;
richTextBox1.SelectionColor = Color.Black;
You can see the Match match4.Yes,each one containing a keyword match.Code work very well when it found if or while.But only $ is blue while the characters behind the '$' is black
I have seen using Regex.
Second problem is if I'm in line 3,I want to move up the line 2 to edit the text.
Starting position of the new characters are always the last line in rich text.