‘He Who Seeks Finds.’ — WordsProcessing Library

With the last release, R2 2021, we added a full-fledged Search functionality in the RadWordsProcessing library. Let’s take a deeper dive.


This content originally appeared on Telerik Blogs and was authored by Martin Velikov

With the last release, R2 2021, we added a full-fledged Search functionality in the RadWordsProcessing library. Let’s take a deeper dive.

Looking for Text in Your RadFlowDocument?

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

What’s New

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:

  • FindAll(string text, bool matchCase=true, bool matchWholeWord=false)

And the second one finds all occurrences of a matched text by the specified regex:

  • FindAll(Regex 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.

Example

Using the already mentioned FindAll() method, we will get all the FindResults within the document:

RadFlowDocument document = ImportOrCreateDocument();
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
ReadOnlyCollection<FindResult> findResults = editor.FindAll("Word", matchCase: true, matchWholeWord: false);

When we already have the collection of the results, we could iterate them and print the matched content on the console:

for (int i = 0; i < findResults.Count; i++)
{
FindResult result = findResults[i];
if (i == 0)
{
Console.WriteLine($"FullMatchText: {result.FullMatchText}");
Console.WriteLine();
}
Console.WriteLine($"Result #{i + 1}");
string runText = result.Runs[0].Text;
int start = result.RelativeStartIndex;
int end = result.RelativeEndIndex;
string textBefore = runText.Substring(0, start);
string machedText = runText.Substring(start, end - start + 1);
string textAfter = runText.Substring(end + 1);
Console.WriteLine($"{textBefore}<<{machedText}>>{textAfter}");
Console.WriteLine();
}

Here’s what the first several results will look like on the console:

BlogPost WordsProcessing Search 01 - text results

Or something similar developed in a WPF project:

BlogPost WordsProcessing Search 02

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.

Try RadWordsProcessing Yourself

Get yourself a free trial of Telerik Document Processing today and start developing your apps better, faster and more easily.

Start My Trial

Share Your Feedback

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.


This content originally appeared on Telerik Blogs and was authored by Martin Velikov


Print Share Comment Cite Upload Translate Updates
APA

Martin Velikov | Sciencx (2021-07-08T10:33:00+00:00) ‘He Who Seeks Finds.’ — WordsProcessing Library. Retrieved from https://www.scien.cx/2021/07/08/he-who-seeks-finds-wordsprocessing-library/

MLA
" » ‘He Who Seeks Finds.’ — WordsProcessing Library." Martin Velikov | Sciencx - Thursday July 8, 2021, https://www.scien.cx/2021/07/08/he-who-seeks-finds-wordsprocessing-library/
HARVARD
Martin Velikov | Sciencx Thursday July 8, 2021 » ‘He Who Seeks Finds.’ — WordsProcessing Library., viewed ,<https://www.scien.cx/2021/07/08/he-who-seeks-finds-wordsprocessing-library/>
VANCOUVER
Martin Velikov | Sciencx - » ‘He Who Seeks Finds.’ — WordsProcessing Library. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/07/08/he-who-seeks-finds-wordsprocessing-library/
CHICAGO
" » ‘He Who Seeks Finds.’ — WordsProcessing Library." Martin Velikov | Sciencx - Accessed . https://www.scien.cx/2021/07/08/he-who-seeks-finds-wordsprocessing-library/
IEEE
" » ‘He Who Seeks Finds.’ — WordsProcessing Library." Martin Velikov | Sciencx [Online]. Available: https://www.scien.cx/2021/07/08/he-who-seeks-finds-wordsprocessing-library/. [Accessed: ]
rf:citation
» ‘He Who Seeks Finds.’ — WordsProcessing Library | Martin Velikov | Sciencx | https://www.scien.cx/2021/07/08/he-who-seeks-finds-wordsprocessing-library/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.