Free Support Forum -

IReplacingCallback Alternative


I have a situation where I am not able to directly refernce the aspose.words.dll library. I am having to embed it as a resource and then load it at runtime and do my operations. Works great but I have run into a limitation.

I need to do search & replace of a regular expression. Since I am using reflection and loading the dll at runtime, I cannot pre-define a class that inherits from IReplacingCallback and pass that as an arguement.

Is there any other way that I can do a search for a regular expression, get returned a list of nodes and I iterate over them and do the replacements needed?



Hi Kunal,

Thanks for your request. Unfortunately, there is no other way to get list of nodes in match without using IReplacingCallback. But if you just need to find and replace some values, you can use overload that takes a string as the second parameter:

Hope this might help you.

As an another option you can create your own find/replace engine. For example as a first step, you can convert document to simple text, then find index where the searched substring starts, then iterate over nodes and convert them to text one by one, while length of string will not be greater or equal the index you found earlier.

Best regards,