My goal is to color all words that are within double quotation marks, and the quotation marks too!
For example: "This text needs to be colored".
My goal is to color all words that are within double quotation marks, and the quotation marks too!
For example: "This text needs to be colored".
You can use Regex
to select double-quoted strings and then colorize them
Ex:
private void ColorirRichTextBox()
{
string[] linhas = richTextBox1.Lines;
foreach (var item in linhas)
{
System.Text.RegularExpressions.MatchCollection matchs = System.Text.RegularExpressions.Regex.Matches(item, @"""[^""\]*(?:\.[^""\]*)*""");
foreach (System.Text.RegularExpressions.Match match in matchs)
{
string mystring = match.Value;
if (richTextBox1.Find(mystring) > 0)
{
int my1stPosition = richTextBox1.Find(mystring);
richTextBox1.SelectionStart = my1stPosition;
richTextBox1.SelectionLength = mystring.Length;
richTextBox1.SelectionColor = Color.Red;
}
}
}
}