New to Telerik Document ProcessingStart a free 30-day trial

Replace existing text with Inline element

Updated on Feb 19, 2026
Product VersionProductAuthor
2020.1.310RadWordsProcessingMartin Velikov

Description

Introducing a way to replace text with other document elements.

Solution

To achieve this we will iterate the document elements of type Run and will compare their text with the desired string. If there is a match we will store the Run index and we will insert the desired element (in our example: Break on this specific index in the Inlines collection. Finally we will 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);
		}
	}
In this article
DescriptionSolution
Not finding the help you need?
Contact Support