Replace Text with Document Elements
RadWordsProcessing gives you the ability to search for a string in a RadFlowDocument instance and replace all matches with specified blocks or inlines.
You can search and replace text using RadFlowDocumentEditor. This article lists the available methods and describes how you can use them.
RadFlowDocumentEditor exposes the ReplaceText() method to enable you to find and replace all instances of a specified string. You can choose between several overloads that allow you to replace the matched text with one or more blocks (tables or paragraphs) or inlines (runs, images, annotation marker).
This functionality is available with R3 2021.
Replace Text with One or more Inlines
- ReplaceText(string oldText, InlineBase inline, bool matchCase = true, bool matchWholeWord = false): Replaces all occurrences of the specified string with a single inline. The last two parameters are optional. If these parameters are not set, the default values are true for matchCase and false for matchWholeWord.
- ReplaceText(string oldText, IEnumerable<InlineBase> inlines, bool matchCase = true, bool matchWholeWord = false): Replaces all occurrences of the specified string with a list of inlines. The last two parameters are optional. If these parameters are not set, the default values are true for matchCase and false for matchWholeWord.
- ReplaceText(Regex regex, InlineBase inline): Replaces all matches of the passed Regex with a single inline.
- ReplaceText(Regex regex, IEnumerable<InlineBase> inlines): Replaces all matches of the passed Regex with multiple inlines.
Example 1: Replace text with a single inline
Example 2: Replace text with multiple inlines
Replace Text with One or more Blocks
- ReplaceText(string oldText, BlockBase block, bool matchCase = true, bool matchWholeWord = false): Replaces all occurrences of the specified string with a single block. The last two parameters are optional. If these parameters are not set, the default values are true for matchCase and false for matchWholeWord.
- ReplaceText(string oldText, IEnumerable<BlockBase > blocks, bool matchCase = true, bool matchWholeWord = false): Replaces all occurrences of the specified string with a list of blocks. The last two parameters are optional. If these parameters are not set, the default values are true for matchCase and false for matchWholeWord.
- ReplaceText(Regex regex, BlockBase block): Replaces all matches of the passed Regex with a single block.
- ReplaceText(Regex regex, IEnumerable<BlockBase> blocks): Replaces all matches of the passed Regex with multiple blocks.