We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

New Line while doing the replace in docx

Hi,


I tried to replace a string with a multiple lines content but without success.

I used \n, but the output just as a space instead of starting a new line, please help.


doc.Range.Replace("<>", “John\nSmith\n1 Abc Street\n XYZ 123456”, new Aspose.Words.Replacing.FindReplaceOptions(FindReplaceDirection.Forward));

output: <span lang=“EN-US” style=“font-size:8.0pt;
mso-bidi-font-size:10.0pt;font-family:“Tahoma”,sans-serif”>John Smith 1 Abc
Street XYZ 123456

<span lang=“EN-US” style=“font-size:8.0pt;
mso-bidi-font-size:10.0pt;font-family:“Tahoma”,sans-serif”><o:p></o:p>

Hi there,

Thanks for your inquiry. Please use following code example to get the desired output. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");

doc.Range.Replace("<>", "John\nSmith\n1 Abc Street\n XYZ 123456".Replace("\n", ControlChar.LineBreak), new Aspose.Words.Replacing.FindReplaceOptions(FindReplaceDirection.Forward));

doc.Save(MyDir + "out v16.12.0.docx");