Author Topic: Get all charranges starting with a digit in richtext edit  (Read 188 times)

rc

  • Regular Member
  • *
  • Posts: 16
Get all charranges starting with a digit in richtext edit
« on: November 02, 2019, 02:16:00 AM »
Hello community,

is there an easy way to get all strings starting with a digit in a rich text control?
I want to parse the text in a rich text edit control and get all charranges starting with a digit. CHARRANGE.
I've already implemented a simple "Find Text" feature in my editor so the user can search for text in their document. I just thought finding text starting with a digit must work similar.

What i want to do is implement a very simple highlighter that highlights digits, strings and comments. So that it is very universal.
So analog i need to check somehowe if it is a comment (starting with ;) or a string (inbetween quotes)

The rules would be:
- check if it is a comment -> highlight comment, else:
    - check if it is a string (inbetween quotes) -> highlight string, else:
        - check if it starts with a digit (e.g. 41h) -> highlight digit

Or:
- check if digit and not within a comment or string -> highlight digit
- check if string (inbetween quotes) and not inside comment -> highlight string
- check if comment -> highlight comment

The problem is, how do i get the charranges of a text inbetween quotes, or a comment starting with ; and the end of line or a text starting with a digit and the last character of that text.

jj2007

  • Member
  • *****
  • Posts: 9802
  • Assembler is fun ;-)
    • MasmBasic
Re: Get all charranges starting with a digit in richtext edit
« Reply #1 on: November 02, 2019, 02:45:07 AM »
- use the EM_GETTEXTLENGTHEX message to know the length of your text
- allocate a buffer
- use the EM_GETTEXTEX message to load your text into the buffer
- parse the buffer

nidud

  • Member
  • *****
  • Posts: 1800
    • https://github.com/nidud/asmc
Re: Get all charranges starting with a digit in richtext edit
« Reply #2 on: November 02, 2019, 04:47:38 AM »
There's an example using syntax highlighting in a rich edit control here:

https://github.com/nidud/asmc/tree/master/source/test/wininc/RichEdit3

« Last Edit: November 02, 2019, 07:26:54 AM by nidud »

rc

  • Regular Member
  • *
  • Posts: 16
Re: Get all charranges starting with a digit in richtext edit
« Reply #3 on: November 03, 2019, 07:18:43 PM »
That's a good example, thanks :)