Need help - Aspose find and replace functionality - find text with new line characters

Test 101.docx (35.9 KB)

Hi,

We are using a licensed version of Aspose.Words (22.4).

I am trying to search and replace the below text in the document. But, the Aspose replace function is not able to find and replace the text in the document.


[SERVICE WAITING PERIOD:

[[30 days] of Active continuous service.]]


I am using the below code, where

rule.MergeField = "[SERVICE WAITING PERIOD:\r\n[[30 days] of Active continuous service.]]";
mergedDocument.Range.Replace(rule.MergeField.Replace("\n", "&l").Replace("\r", "&p"),
    "abc", new Aspose.Words.Replacing.FindReplaceOptions()
    { MatchCase = false, FindWholeWordsOnly = false });[quote="HealthcareInteractive, post:1, topic:247378, full:true"]

Test 101 - Result.docx (36.8 KB)
Test 101 -Input.docx (36.8 KB)

Hi,

These are the input and output files that I need to generate. We basically need to search the content inside the brackets and keep/remove from the document based on user input.

Here are our processing steps:

  1. Client give us these input documents and we upload in our system
  2. there is an importer which reads all the brackets ‘[]’ and subbrackets (meaning bracketed content inside a large parent bracket) and saves them in the database with unique bracket Id and bracket content
  3. this document is later presented to a reviewer on our web platform where we convert the document into HTML and show all the bracket rules loaded at step 2. The reviewer here will take some action on each of these brackets. Like Keep/Delete/Change. These actions are saved into the database.
  4. The final processing step is where I need to search and replace this based on reviewers input to either keep it([] will be removed) or remove it altogether from the document. I have figured out for new lines \r\n and tabes \t with help from other forums, but I am not sure how to search and replace content as attached which has cell breaks and \r and other chars present.

Please suggest.

@HealthcareInteractive I am afraid, it is not possible to achieve what you need using simple find/replace functionality. You cannot match content that includes tables. In case when content between brackets contain table, you have to use Document Object Model to process such content, i.e. match the open bracket and closing bracket and then process the content between them. I think, the example provided in the article about extracting content between nodes might be useful for you.
Also, I think using bookmarks might simplify processing of the document, i.e. you can insert bookmark that starts where opening bracket is and ends where closing bracket is.

thanks Alexey. I will analyze these options with my team and get back to you on further queries.

1 Like