Free Support Forum - aspose.com

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

Hi,

We have one strange issue when searching for a word and replacing it. We have tested this in Aspose.Words latest 21.6.0.0 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 Variable.name and Variable.city are separated by new line (pressing Enter key in keyboard), and Variable.city and Variable.zip are separated by Shift+Enter from keyboard. Only Variable.name is finding and replacing, the rest are not.

Can you please tell us what was the work arround without modifying the template?

Template1.zip (65.0 KB)

@srinudhulipalla,

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, Variable.city is a whole word. So, the question is again why Variable.city and Variable.zip are not found and replcaed when these words in two different lines.

@srinudhulipalla,

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.