What is an effective way to autocolor text in i.e. a HTMLEditor textbox and have certain words colored?
I've done this years ago in C++/CLI and with hundreds of words it took a long time to process every word so there must be a more effective way to do it than to loop through all words. One idea might be to reset a counter value each time the user presses spacebar and store what is typed in a string untill spacebar is pressed again then check the string for a matching word and color what's being typed by checking the start and lenght of the string, that way each words can be processed on the fly as you type. That could perhaps remove the looping process which tends to be very time consuming. Since autocoloring of text is implemented in the B4X IDE I kindly ask Erel for advice on how to do this, but everybodys comments are of course welcomed so that others can learn how to do this.
I found an example made in Visual Basic years ago to give you an idea of what I want to achieve:
Original VB code
Any advice is very appreciated. Thanks
I've done this years ago in C++/CLI and with hundreds of words it took a long time to process every word so there must be a more effective way to do it than to loop through all words. One idea might be to reset a counter value each time the user presses spacebar and store what is typed in a string untill spacebar is pressed again then check the string for a matching word and color what's being typed by checking the start and lenght of the string, that way each words can be processed on the fly as you type. That could perhaps remove the looping process which tends to be very time consuming. Since autocoloring of text is implemented in the B4X IDE I kindly ask Erel for advice on how to do this, but everybodys comments are of course welcomed so that others can learn how to do this.
I found an example made in Visual Basic years ago to give you an idea of what I want to achieve:
Original VB code
B4X:
RichTextBox1.SelectionColor = Color.Blue
Dim word As String = "potato"
If RichTextBox1.Find(word) > 0 Then
Dim position As Integer = RichTextBox1.Find(word)
RichTextBox1.SelectionStart = position
RichTextBox1.SelectionLength = word.Length
RichTextBox1.SelectionColor = Color.Blue
RichTextBox1.SelectionStart = RichTextBox1.Text.Length
End If
Any advice is very appreciated. Thanks