I have a Document i want to Search for a Specific Variable.
I need to get the parent container/block of the text.
thx
1 Answer, 1 is accepted
0
Petya
Telerik team
answered on 31 Jul 2015, 01:37 PM
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.
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)
{
paragraphText.Append(run.Text);
}
}
string text = paragraphText.ToString();
if (text.Contains(searchedText))
{
return paragraph;
}
}
return null;
}
I hope this helps.
Regards,
Petya
Telerik
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