Updating Old Aspose.Word with latest 19.9 dll

As per your saying that ‘we do not provide support for older releases of Aspose APIs’.
Now we are updating old Aspose.Words with latest 19.9 dll but unable to convert code.

Can you please help me to convert the below code:

Aspose.Words.Document doc = new Aspose.Words.Document(s, loadOptions);

strToReplace = string.Concat("/s/", string.Concat(FirstName == null ? “” : string.Concat(FirstName + " "), MiddleName == null ? “” : string.Concat(MiddleName, " "), LastName == null ? “” : LastName));

                            doc.Range.Replace("/s/", strToReplace, false, false);

                            Regex reg = new Regex(strToReplace, RegexOptions.IgnoreCase);
                            doc.Range.Replace(reg, new ReplaceEvaluatorFindAndHighlight(), true);

@amanjainmccalla

We suggest you please read the following article.
Find and Replace

We have modified your code snippet according to latest API of Aspose.Words. Hope this helps you.

LoadOptions loadOptions = new LoadOptions();

Aspose.Words.Document doc = new Aspose.Words.Document("", loadOptions);

String strToReplace = "........";

FindReplaceOptions findReplaceOptions = new FindReplaceOptions();
doc.Range.Replace("/s/", strToReplace, findReplaceOptions);

Regex reg = new Regex(strToReplace, RegexOptions.IgnoreCase);
findReplaceOptions.ReplacingCallback = new ReplaceEvaluatorFindAndHighlight();
doc.Range.Replace(reg, "", findReplaceOptions);
1 Like

Thank you so much for your promt response.
Can you please explain this below line ? will it replace the matched string to empty ? I don’t want to replace anything. I just want to highlight the matched string with the use of call back function ?
doc.Range.Replace(reg, “”, findReplaceOptions);

@amanjainmccalla

The second parameter of Range.Replace method is a string to replace all occurrences of pattern.You have implemented IReplacingCallback interface. Its mean that you want to have your own custom method during a find and replace operation. So, this parameter should be empty. Please read the following article.
How to Find and Highlight Text

1 Like

Got it tahir. Thank you so much.

@amanjainmccalla

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.