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

Free Support Forum - aspose.com

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].


@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();
Paragraph para1 = new Paragraph(tempDoc1);
para1.Runs.Add(new Run(tempDoc1) { Text = "We have audited the [FinancialStatements] financial statements of [CompanyName]." });
Node tempNode1 = tempDoc1.GetChild(NodeType.Run, 0, true);

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

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

Document doc2 = (Document)tempDoc2.Clone(false);
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.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))