StringIndexOutOfBounds while Replacing

Hello there,


I recently tried to update from Aspose Words version 13.9 to 13.12 but encountered some problems. I managed to track them down to the Replacer throwing an IndexOutOfBounds.

Please find attached a test case where I reproduced it with both the 13.11 and 13.12 release of Aspose Words. In versions prior to 13.11 it works perfectly well.

Can you please check if this is a bug or a feature and whether I am doing something wrong there?

Best regards,
Grendel
Hi Grendel,

Thanks for your inquiry. This issue does not occur if you use backward evaluation instead of forwards in your code. This is just a matter of changing the third parameter of the replace method to false. In your ImageReplacer.execute method, please change the code as follows:

doc.getRange().replace(pattern, new ImageReplaceWorker(), false);

Generally it is recommend if you are modifying the document in a custom replacement evaluator then you should use backward replacement.

I hope, this helps.

Best regards,

Hi Awais,


thank you very much. It works perfectly. I’ll try to remember using the backward option from now on, even if the other one seems to work :slight_smile:

Best regards