Find String in Document, return Block

2 posts, 0 answers
  1. Florian
    Florian avatar
    14 posts
    Member since:
    Dec 2014

    Posted 29 Jul 2015 Link to this post

    Hi there.


    I have a Document i want to Search for a Specific Variable.

    I need to get the parent container/block of the text.



  2. Petya
    Petya avatar
    983 posts

    Posted 31 Jul 2015 Link to this post

    Hi Florian,

    Are you expecting that the strings you're going to search for will be short and in a single paragraph?

    This functionality is currently not available in the library and I logged it in our backlog for future consideration: Implement Find (Search) Functionality. You could, however, enumerate the Run elements in all paragraphs and append their text together. This will allow you to implement a text-based search and find the paragraph a particular string is in. 

    Here is a simple example showing what I have in mind.
    private Paragraph FindparagraphContainingText(RadFlowDocument document, string searchedText)
        foreach (var paragraph in document.EnumerateChildrenOfType<Paragraph>())
            StringBuilder paragraphText = new StringBuilder();
            foreach (var inline in paragraph.Inlines)
                Run run = inline as Run;
                if (run != null)
            string text = paragraphText.ToString();
            if (text.Contains(searchedText))
                return paragraph;
        return null;

    I hope this helps.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top