Exception When calling replace with "\r"


I’m trying to find a way to join two paragraphs together.

Something I have tried is to Replace “\r” in a paragraph range with “”. But this causes an NullReferenceException. I am using the evaluation version of Aspose.Words for .NET.

The code I am trying is

documentBuilder.CurrentParagraph.Range.Replace("\r", "", false, false);

I can replace other characters like \t.

Is there a way to join two paragraphs?

Yours Spencer.

Thanks for your request. Unfortunately, Aspose.Words does not allow using special characters in a captured or replacement string. An exception is thrown if a captured or replacement string contain one or more special characters: paragraph break, cell break, section break, field start, field separator, field end, inline picture, drawing object, footnote:
If you need to concatenate two paragraphs, you should just copy all content from the second paragraph into the first one and then remove the second empty paragraph. For instance, see the following code:

// Open document.
Document doc = new Document(@"Test001\in.doc");
// Get paragraphs that we need to concatenate.
// Let it be the first and the second paragraphs.
Paragraph first = doc.FirstSection.Body.Paragraphs[0];
Paragraph second = doc.FirstSection.Body.Paragraphs[1];
// Move all content from the second paragraph into the first.
while (second.HasChildNodes)
// Remove the second paragraph.
// Save output.

Hope this helps.
Best regards,

The issues you have found earlier (filed as WORDSNET-1252) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.