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 (https://docs.microsoft.com/en-us/windows/win32/api/richedit/ns-richedit-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.
- 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
deleted
That's a good example, thanks :)