DocumentTextSearch bug?

3 posts, 0 answers
  1. Roy
    Roy avatar
    2 posts
    Member since:
    May 2012

    Posted 04 Feb 2014 Link to this post

    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. Yancho
    Admin
    Yancho avatar
    72 posts

    Posted 07 Feb 2014 Link to this post

    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).

  3. UI for WPF is Visual Studio 2017 Ready
  4. Roy
    Roy avatar
    2 posts
    Member since:
    May 2012

    Posted 10 Feb 2014 in reply to Yancho Link to this post

    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
Back to Top