How to replace multi line text using .NET

Hi Team,


I am using ProcessingDocument.Range.Replace(variable, value, isMatchCase, false); function for find and replace operation in Aspose Word.

But it is not working with multiline string .

The error message states that line break character not allowed.

Please help in this case.

This is high priority, I will post same in priority forum.

Regards,
Nakul

Hi Nakul,

Thanks for your query. It would be great, If you share your document along with code for investigation purposes.

Hi Tahir,

It is straight…
I am getting exception while replacing multi line string…

I am using below code to replace the specified string. and find attached input template.

string textToReplace = “Hi team,\r\n This is text message from Nakul.\r\n Thanks”;
ProcessingDocument.Range.Replace("##WELCOMENOTE##", textToReplace , isMatchCase, false);

I get below exception.

System.ArgumentException: 'The replace string cannot contain special or break characters.'

Please find attached input document.

Hope it is clear now.

-Nakul

Hi Nakul,

Thanks for sharing the information. Please use the following code snippet for your requirement. Let us know, If you have any more queries.

string textToReplace = "Hi team," + Aspose.Words.ControlChar.LineBreak + " This is text message from Nakul." + Aspose.Words.ControlChar.LineBreak + " Thanks";

doc.Range.Replace("##WELCOMENOTE##", textToReplace, true, false);

Hi,

This is not good solution,

How could i do this with user input.

-Nakul

Hi Nakul,

If you are getting input form user, you can use following code snippet. In following example, I am getting input form user in the text box named txtInput. Hope this helps you.

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

string textToReplace = txtInput.Text.Replace("\r\n", Aspose.Words.ControlChar.LineBreak);

doc.Range.Replace("##WELCOMENOTE##", textToReplace, true, false);

doc.Save(MyDir + @"output.docx");

Please let us know, If you have any more queries.

Hi Nakul,


I noticed you posted this issue on the priority support forum but did not reply to Tahir’s last comment. Did Tahir’s answer help you? Do you still want to escalate this issue?

Thanks,

Hi team,

Sorry for the delayed reply.

It works well, but i would expect to handle such common scenarios inside library.

If it is final solution you can close this issue.

Thanks and Regards,

Nakul

Hi Nakul,

Thanks for this additional information.

It’s great that the code provided will suffice for the mean time. In a future version we will look into improving Range.Replace to support paragraph breaks and other types of breaks. We will inform you of any developments.

Thanks,

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.
(40)