I want to look through a Word document and find all instances of a particular word. I don’t want to replace the word, I just want to know if it exists.
This page suggests Range.Replace “is useful for searching strings without replace”: https://docs.aspose.com/words/net/find-and-replace/
But this page says the return value is the “number of replacements made”: https://reference.aspose.com/words/net/aspose.words/range/replace/
I don’t want to replace anything, I just want to find search without replace. I can do that with the following code:
public class MergeCodeFinder : IReplacingCallback
{
public ReplaceAction Replacing(ReplacingArgs args)
{
args.Replacement = args.Replacement;
return ReplaceAction.Replace;
}
}
Setting args.Replacement = args.Replacement just to get the count of “replacements” seems a bit silly. Am I missing something? Is there an easier way to find something in a document without replacing it?