Replace Range Document when Document has newline break

Hi,

I have an Aspose word document that has keys and values to replace.
I need to use Range.Replace method with these parameters --> (Regex, |ReplacingCallback,isForward)
It replace all newline characters in the document when i try to replace characters as vbCr, ControlChar.LineBreak, ChrW(7).
Here is a sample about my issue

Private gWordDocument As Aspose.Words.Document
Dim _html As New ReplaceWithHtmlEvaluator
_html.Tag_Value = pTagValue 'this is the tag itself
_html.Tag_ID = pTagID



        gWordDocument.Range.Replace(New Regex(pTagValue), _html, False)

My pTagValue string is
“[ENV:{acik adres}” & vbCr & “/]”

When i check gWordDocument.Range my string is like
“[ENV:{acik adres}” & vbCr & “/]”.

[ENV:{acik adres} /here has a newline break on my word document/
/]

This is the error {“The match includes one or more special or break characters and cannot be replaced.”}

I have searched on this forum but could not find any solution. Waiting for your response.
I prepare a sample about this code if you need it.
Have a nice forums.

@zelihaserbez

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

There are two different input for this project and they are into the …\Example\Example\bin\Debug.
I wrote a description about two of these inside of project.
Thanks and have a nice forum.

Edit: I couldn’t upload my document from your tool. Here is a download link from my google drive. I hope this works.

https://drive.google.com/open?id=1q-5Me1p0nczOknWC8KfLGiSwdxwqh7R5

@zelihaserbez

Thanks for sharing the detail. We have tested the scenario using the shared application and have not faced any exception.

We suggest you please use the latest version of Aspose.Words for .NET 19.3 and updated method of Range.Replace as shown below.

Dim opt = New FindReplaceOptions()
opt.ReplacingCallback = _html
worddoc.gWordDocument.Range.Replace(New Regex(Escape_For_Regex(_html.Tag_Value)), "", opt)
worddoc.Create_Final_Document(output_path, err)

Hi again.
I have tried your solution on my project and it didn’t work for me.I updated Aspose.Words Package and have replaced your code lines with mine.
Here is a link again;
https://drive.google.com/open?id=1MQrW8gKE7m7s-jeyoTmPq2iJdtdDy6rQ

P.S : Need to use Undesired_Behavior.docx file to get this output.0Undesired_Behavior.pdf (58.8 KB)

Thanks again and have a nice forum.

@zelihaserbez

Please remove DLL files from your ZIP file and create a simplified console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing. Thanks for your cooperation.

Hi.
I removed dll files from my console application and uploaded again. I hope this is helpful for your solution.
Waiting for your response.
Thanks.

https://drive.google.com/open?id=1pLP5gAAurSpAzOPsNlzrqf2q9RKDHTKz

@zelihaserbez

We suggest you please read the following article.
Replace Text using Meta-Characters

You should use special meta-characters if you need to work with breaks:

  • &p - paragraph break
  • &b - section break
  • &m - page break
  • &l - manual line break

Please replace vbCr with &p as shown below to get the desired output.

_html.Tag_Value = "[ENV:{acik adres}&p/]"

Hi again. Thanks for your solution. This is worked for me. Have a nice day.