Advertisement Jump to content
Sign in to follow this  

CAtlRegexp and .NET RichTextBox [SOLVED]

This topic is 3869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm calling from .NET into a C++ DLL and I'm trying to match a regex using the CAtlRegexp class. That works and I get back the correct matching text as well as the offset and length of the text. However, when I try to select the text in a .NET RichTextBox using the offset and length that was returned, it's off by a number of characters(how many depends on how long the text is, eg for a 24KB block of text it's off by 575 characters). The offset seems to be incorrect even though CAtlRegexp returns the correct matched text, and the length is correct as well. Edit: After testing this with the .NET Regex class, it's giving the same problem.
Here's how to reproduce it:
1.Take the HTML for the international homepage and match "<IMG height=110 alt=Google" without the quotes. 
2.Put the HTML into the RichTextBox and then call the RichTextBox.Select method passing in the Index and Length of the System.Text.RegularExpressions.Match object.

Anyone have any idea what's going wrong?> Edit 2: Found the problem. RichTextBox counts \r\n as one character whereas the regex classes count it as 2. Problem solved. [Edited by - deathtrap on June 18, 2008 5:42:09 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!