Cannot replace linebreak

Hi all, I’m using Aspose.word version 18.9.0 and I am unable to replace line break. I tried with many characters but none of them work. Please help

        Document doc = new Document("input.docx");

        doc.Range.Replace("AAAA" + ControlChar.LineBreak, "string.Empty", _options);
        doc.Range.Replace("AAAA" + ControlChar.ParagraphBreak, "string.Empty", _options);
        doc.Range.Replace("AAAA" + ControlChar.SectionBreak, "string.Empty", _options);

        doc.Range.Replace("AAAA" + ControlChar.LineBreakChar, "string.Empty", _options);
        doc.Range.Replace("AAAA" + ControlChar.PageBreakChar, "string.Empty", _options);
        doc.Range.Replace("AAAA" + ControlChar.ParagraphBreakChar, "string.Empty", _options);
        doc.Range.Replace("AAAA" + ControlChar.SectionBreakChar, "string.Empty", _options);

        doc.Save("output.docx");

@fcmtuan

Please use the latest version of Aspose.Words for .NET 19.10. If you still face problem, please ZIP and attach your input Word document here for testing. We will investigate the issue and provide you more information about your query.

ConsoleTestLineBreak.zip (74.3 KB)
I update to newest version 19.10 but it still doesn’t work. Please help to investigate.

@fcmtuan

Please use special meta-characters to work with breaks:

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

Following code snippet shows how to use it. Hope this helps you.

doc.Range.Replace("AAAA&l", "", _options);
doc.Range.Replace("AAAA&p", "", _options);
1 Like

Thanks, it works for me.