Hi to all,
I have a problem when I try to use Aspose.Words.dll to perform replacement, i.e, the output of replacement does not work.
For example, the codes in VB.Net as follow:
--------------code begin------------------------
Dim doc As New Aspose.Words.Document(“C:\Test.docx”)
doc.Document.Range.Replace(Aspose.Words.ControlChar.LineBreakChar, Chr(13), False, False)
doc.Document.Range.Replace(Aspose.Words.ControlChar.LineBreakChar, vbCrLf,False, False)
doc.Save(“C:\Test2.docx”)
-------------code end---------------------------
However, the replacement result is out of expectation,i.e., the LineBreakChars are still in the document, no replacement has been performed.
Who can help to how to perform this replacement.
Thanks!
Chen
@jixuecheng
Thank you for your inquiry. You can replace the line breaks at document level and at Paragraph levels or both by using Replace with FindReplaceOptions. Please have at look at this sample code for document level replace.
Dim doc As New Aspose.Words.Document("E:\Aspose\Test.docx")
Dim findReplaceOptions As New FindReplaceOptions()
findReplaceOptions.MatchCase = False
findReplaceOptions.Direction = FindReplaceDirection.Forward
doc.Document.Range.Replace(New Regex(ControlChar.LineBreak), "", findReplaceOptions)
doc.Save("E:\Aspose\Test2.docx")
Please also provide us your Input document and expected output document for more specific solution.
Hi, rizwan.niazi,
Thank you very much for your answer. It works!
But the code such as ‘Dim findReplaceOptions As New FindReplaceOptions()’ must be modified as " Dim findReplaceOptions As New Replacing.FindReplaceOptions()" based on the dll (Version=V16.0.0.0.0)
@jixuecheng
Thank you for your feedback. We are glade to hear that it works for you and we suggest you to upgrade to latest version for better experience - Aspose.Words for .NET 17.12.