New to Telerik Document Processing? Start a free 30-day trial
Replace Existing Text with Inline Element
Updated on Jun 9, 2026
Environment
| Version | Product | Author |
|---|---|---|
| 2020.1.310 | RadWordsProcessing | Martin Velikov |
Description
This article describes how to replace text with other document elements.
Solution
To achieve this, iterate the document elements of type Run and compare their text with the desired string. If there is a match, store the Run index and insert the desired element (in this example a Break) at that specific index in the Inlines collection. Finally, remove the Run.
csharp
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
editor.InsertText("First line");
editor.InsertText("NewLine");
editor.InsertText("Second line");
foreach (Run run in document.EnumerateChildrenOfType<Run>().ToList())
{
if (run.Text == "NewLine")
{
Paragraph paragraph = run.Paragraph;
int childIndex = paragraph.Inlines.IndexOf(run);
Break br = new Break(document);
br.BreakType = BreakType.LineBreak;
paragraph.Inlines.Insert(childIndex, br);
paragraph.Inlines.Remove(run);
}
}