Replace new line character in new paragraph docx in java

Hi there ,

how can i replace String with another String and if replacement String contains ‘\n’ then place text after \n to next paragraph with same format in docx. replacement string may also contain \t.

Also want to know what is ControlChar.LINE_FEED and ControlChar.LINE_BREAK and their impact.

currently if i directly pass replacement as shown in below code.
doc.getRange().replace(“mad”, “abc\nxyz”, new FindReplaceOptions(FindReplaceDirection.FORWARD));
then there is some space shown on ms word and soft enter in libre-office.

@parthu,

Thanks for your inquiry. The ControlChar class control characters often encountered in documents. The ControlChar.LineBreak represents line break character and ControlChar.LineFeed represnt line feed character.

You can replace “\n” with ControlChar.ParagraphBreak using Range.Replace method. If you still face problem, please share your input and expected output documents here for our reference. We will then provide you more information on this.

Thanks for solution.

@parthu,

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

A post was split to a new topic: ControlChar.LineBreak behaves differently in windows machine and Linux machine