Compare two paras and accept only some revision in Dot net

Hi Team,

We need to implement the following functionality with Aspose license. Say have a para and call it as Initial, here there will be some text in square braces and same para is altered and say final now I have to compare the initial vs final and accept only the changes in non-square braces. Is there a logic to do this with Aspose word, kindly let me know the possibility.

Para 1 Before change:
We have audited the [FinancialStatements] financial statements of [CompanyName].

Para 1 After change:
We have reviewed and audited the consolidated financial statement of ABC limited.

After comparing:
We have reviewed and audited the [FinancialStatements] financial statement of [CompanyName].

Regards,
Karthikeyan

@Karthik_Test_account based in your example what do you want to achieve is almost impossible, the result text is a random subset of the original text and the modified text, there is not visible rule to apply to format the resultant text. Said that, probably the best way to achieve what you want is using Aspose Compare Documents feature and after that work with the revisions. Please use as reference the following code example:

Document tempDoc1 = new Document();
tempDoc1.FirstSection.Body.RemoveAllChildren();
Paragraph para1 = new Paragraph(tempDoc1);
para1.Runs.Add(new Run(tempDoc1) { Text = "We have audited the [FinancialStatements] financial statements of [CompanyName]." });
tempDoc1.FirstSection.Body.AppendChild(para1);
Node tempNode1 = tempDoc1.GetChild(NodeType.Run, 0, true);

Document tempDoc2 = new Document();
tempDoc2.FirstSection.Body.RemoveAllChildren();
Paragraph para2 = new Paragraph(tempDoc2);
para2.Runs.Add(new Run(tempDoc2) { Text = "We have reviewed and audited the consolidated financial statement of ABC limited." });
tempDoc2.FirstSection.Body.AppendChild(para2);
Node tempNode2 = tempDoc2.GetChild(NodeType.Run, 0, true);

Document doc1 = (Document)tempDoc1.Clone(false);
doc1.EnsureMinimum();
doc1.FirstSection.Body.FirstParagraph.AppendChild(doc1.ImportNode(tempNode1, true, ImportFormatMode.UseDestinationStyles));

Document doc2 = (Document)tempDoc2.Clone(false);
doc2.EnsureMinimum();
doc2.FirstSection.Body.FirstParagraph.AppendChild(doc2.ImportNode(tempNode2, true, ImportFormatMode.UseDestinationStyles));

doc1.Compare(doc2, "Author", DateTime.Now);

// No changes detected
if (!doc1.Revisions.Any()) return;

List<Revision> revisions = new List<Revision>();

foreach (var revision in doc1.Revisions)
{
    if(revision.RevisionType == RevisionType.Insertion || revision.RevisionType == RevisionType.Deletion)
        revisions.Add(revision);
}

revisions.Where(r => r.RevisionType == RevisionType.Insertion).ToList().ForEach(r => r.Accept());
string pattern = @"\[[^\]]*\]";
revisions.Where(r => r.RevisionType == RevisionType.Deletion).ToList().ForEach((r) => 
{ 
    var text = ((Run)r.ParentNode).Text;
    if(Regex.IsMatch(text, pattern))
    {
        r.Reject();
    }
    else
    {
        r.Accept();
    }
});

doc1.Save("C:\\Temp\\output.docx");