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

Free Support Forum - aspose.com

Aspose Replace Text Keep format

Hello, Support.

I am trying to replace a text in an aspose word document but I can not keep the correct formatting. for example the below string is retrieve from the database:

header = "Name:\t" + row[NAME] + "\n";

header += "ENum:\t" + row[ENUM] + "\n";

header += "Office:\t" + row[OFFICE] + "\n";

header += "Group:\t" + row[GROUP] + "\n";

header += "Sub group:\t" + row[SUBGROUP] + "\n";

When I use the aspose code: Word.FirstSection.Range.Repleace("Header",header,false,true) I am able to replace the code but all the text is replaced in one line as: follows:

[Name: John Doe. ENum: 00000 Office: Washington D.C. Group: Business Subgroup: International Author: ]

I need it to keep each in different lines like this:

Name: John Doe.

ENum: 0000

Office: Washington D.C.

Group: Business

Sub group: International


Please Advice

Hi Abel,

Thanks fou using our products.


I am trying to replace a text in an aspose word document

As your request is related to Aspose.Words, I am moving your request in Aspose.Words forum. My colleagues from Aspose.Words component team will answer you shortly.

We apologize for your inconvenience.

Thanks & Regards,

Hi Abel,

Thank you for inquiry. Please follow up the code snippet as following:

header = "Name:\t" + "John Doe." + ControlChar.LineBreakChar;

header += "ENum:\t" + "0000" + ControlChar.LineBreakChar;

header += "Office:\t" + "Washington D.C." + ControlChar.LineBreakChar;

header += "Group:\t" + "Business" + ControlChar.LineBreakChar;

header += "Sub group:\t" + "International" + ControlChar.LineBreakChar;

Moreover, I will suggest you to visit documentation here.

Thank you very much for your suggestion. It worked as a charmed, I also found a class on one of the thread that does the trick

Hi Abel,

It is perfect that you managed to achieve what you need. Please feel free to ask in case of any issues. We are always glad to help you.