With the last release, R2 2021, we added a full-fledged Search functionality in the RadWordsProcessing library. Let’s take a deeper dive.
Implementing a search functionality was one of the most-demanded features in the RadWordsProcessing library. Now you can check the RadFlowDocument for the occurrences of certain text even if the finding text is split into multiple Runs.
The result of a successful search is a list of all the occurrences of the searched text inside the document. As stated above, the text may be part of single or multiple runs and can contain only a part of them. Also, the search can be executed by using a regular expression (regex) string.
Every occurrence contains a collection of runs, the index of the first character in the searched text inside the first run, the index of the last character in the searched text inside the last run, and the text that is matched (in the case of regex string).
The RadFlowDocumentEditor now provides two brand-new methods for finding occurrences of a specified text.
The first one finds all occurrences of the specified string and can respect match case and match whole word:
And the second one finds all occurrences of a matched text by the specified regex:
Both methods return a collection of FindResult instances.
For more detailed information on this topic and about the replace options, check the Find and Replace Text and Style help article.
Using the already mentioned FindAll() method, we will get all the FindResults within the document:
When we already have the collection of the results, we could iterate them and print the matched content on the console:
Here’s what the first several results will look like on the console:
Or something similar developed in a WPF project:
The screenshot is taken from the Telerik UI for WPF Controls Demo. You can download and check the latest version of this demo on demos.telerik.com/wpf.
Get yourself a free trial of Telerik Document Processing today and start developing your apps better, faster and more easily.
Let’s continue to build the future of Telerik Document Processing together! So, don’t forget to share your thoughts as a comment below or let us know if you have any suggestions and/or need any features or components by visiting our Telerik Document Processing Feedback Portal.
Martin is a Technical Support Engineer, part of the Document Processing team in Sofia, Bulgaria since July 2019. He is passionate about new technologies and is always on the crest of a wave with the novelties. In his spare time, Martin likes travelling to new destinations and exploring new cultures, hanging out with friends, reading books, practicing sports, and more.
Subscribe to be the first to get our expert-written articles and tutorials for developers!