This is a migrated thread and some comments may be shown as answers.

DocumentTextSearch bug?

2 Answers 74 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Roy
Top achievements
Rank 1
Roy asked on 05 Feb 2014, 04:26 AM
Hi,
I am not sure if I am losing it or there is actually a bug with DocumentTextSearch. I have a document for which I want to find a replace some text. all the text that needs to be replace matches this regular expression {{(.*?)}}. Now the code below works for everything except if the text has a number in it. For example, say I want to match {{COM_LDL}}, then this gets matched perfectly. but if i want to match {{COM_LDL1}} then only {{COM_LDL is matched and the rest is disregarded. Below is the code, can somebody please help?
Thanks,
Roy

 DocumentTextSearch search = new DocumentTextSearch(rtb.Document);
                List<TextRange> rangesTrackingDocumentChanges = new List<TextRange>();
                foreach (var textRange in search.FindAll("{{(.*?)}}")) //find all merge fields
                {
                    TextRange newRange = new TextRange(new DocumentPosition(textRange.StartPosition, true), new DocumentPosition(textRange.EndPosition, true));
                    
                    rangesTrackingDocumentChanges.Add(newRange); --> this is where the problem happens.  if there is a number (COM_LDL1) then newRange.StartPosition.ToString() returns "\"{{COM_LDL\"@0" if there isnt a number then newRange.StartPosition.ToString() works perfectly and returns "\"{{COM_LDL}}\"@0"

                }

2 Answers, 1 is accepted

Sort by
0
Missing User
answered on 07 Feb 2014, 05:05 PM
Hi Roy,

Thank you for contacting us!

The given regular expression {{(.*?)}} finds correctly all wanted matches in the document. There is no exception, even if the text has a number in it. Please take a look at the attached demo project.

Probably you are misled by the functionality of the ToString() method, which works perfectly right in the context of the current layout box. To further explain, the match in the document - {{COM_LDL1}} consists of three layout boxes, the first of which holds the {{COM_LDL text and DocumentPosition’s ToString() method returns the position in the current layout box.

I hope this helps! Let me know if you have other comments or questions.

Regards,
Yancho
Telerik

Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).

0
Roy
Top achievements
Rank 1
answered on 11 Feb 2014, 03:14 AM
Hi Yancho,
Thank you very much, you were right, I was misguided by what the "ToString()" function did in this context. I was able to solve the issue using your example.
Cheers,
Roy
Tags
RichTextBox
Asked by
Roy
Top achievements
Rank 1
Answers by
Missing User
Roy
Top achievements
Rank 1
Share this question
or