Find Whole Words & Only then Replace Text in Word Document (C# .NET) | Paragraph & Line Breaks


We have one strange issue when searching for a word and replacing it. We have tested this in Aspose.Words latest version, and I have attached the sample code, input file and expected file.

If you look into the attached input file “Template1.docx” the words and are separated by new line (pressing Enter key in keyboard), and and are separated by Shift+Enter from keyboard. Only is finding and replacing, the rest are not.

Can you please tell us what was the work arround without modifying the template? (65.0 KB)


The problem occurs because you are setting value of FindReplaceOptions.FindWholeWordsOnly property to true. If you set it to false or simply remove following line, the problem will be resolved.

options.FindWholeWordsOnly = true;

Yes, we have set it purpose fully since we would like the replacements happnen only when complete word found, and not the part of the word. If you open the template, is a whole word. So, the question is again why and are not found and replcaed when these words in two different lines.


We have logged this problem in our issue tracking system. Your ticket number is WORDSNET-22364. We will further look into the details of this problem and will keep you updated here on the status. We apologize for any inconvenience.

The issues you have found earlier (filed as WORDSNET-22364) have been fixed in this Aspose.Words for .NET 21.7 update and this Aspose.Words for Java 21.7 update.