how can i change the color of numbers inside of the richtextbox?

poringgunner

Active member
Joined
Feb 23, 2014
Messages
42
Programming Experience
Beginner
it is possible to change the color of numbers in richtextbox?
example.. i have richtextbox that contains a text like this
"i have 50 words inside my richtextbox" //this is the first line of richtextbox.
"and i need only 30 of it" //this is the second line.



i want to change the color of number 50 and 30 to RED color.. but i dont know how to do it.
 
I would use Regex class and its Matches method to find the numbers in text (gives you index and length of each match), then you use RichTextBox method Select(index,length) to select each number and set color with SelectionColor property. Regex expression \d+ should do it.
 
how about change the color of number into a 2 color like this

if the number is greater than or equal to 50.00 then its color will be RED.
if the number is less than 50.00 then it's color will be BLUE.

it is possible?
 
For each number you find you can convert to a relevant numeric data type, for example using int.Parse, and check the value condition.
 
Back
Top Bottom