We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Find Keywords in Word Document and Replace with new Content C# .NET | Split Run Node into Sub Runs


I am working on find and replace with Aspose.Words and used IReplacingCallback to style of found keyword as strikedout and replaced word as underline.

for this I have used SplitRun mentioned. Here the issue is SplitRun is not splitting into sub runs.
for example in the run.text = “this agreement (“AGREEMENT”) is for” will split only first occupancy thus only replacing the first find keyword (“agreement”) with no case match.

How can I do subruns to find and replace all the occurrence in 1 sentence?

here is the split run code.

    private static Run SplitRun(Run run, int position, string replacingWord)
        Run afterRun = (Run)run.Clone(true);
        if (run.Text.Length > position && run.ParentNode != null)
            afterRun.Text = run.Text.Substring(position);
            run.Text = run.Text.Substring(0, position);
            run.ParentNode.InsertAfter(afterRun, run);
        return afterRun;


Please ZIP and attach the following resources here for testing:

  • Your simplified input Word document
  • Aspose.Words for .NET 20.9 generated output DOCX file showing the undesired behavior
  • Your expected DOCX file showing the desired output. You can create this document manually by using MS Word.
  • Please also create a standalone simple Console application (source code without compilation errors) that helps us to reproduce your current problem on our end and attach it here for testing. Please do not include Aspose.Words DLL files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start further investigation into your particular scenario/issue and provide you more information.