We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Incorrect match node range in ReplaceEvaluatorArgs

Using this sample code and attached file I tried to replace some text ("" as sample) with some any elemnt, but e.MatchNode.Range has invalid part of finded text (only some matches has right text and only if searching from end to beginning). Match is sucess, but Range is invalid.
C# code:

private void SomeMethod()
    Document doc = new Document("sample.rtf");
    doc.Range.Replace(new Regex(@"<(?[a-zA-Z0-9_:!]+)>"), new ReplaceEvaluator(ReplaceText), false);
    // ...
private ReplaceAction ReplaceText(object sender, ReplaceEvaluatorArgs e)
    // some logic here
    // but for attached sample first occurance^
    // e.Match = ""
    // e.MatchNode.Range.Text = "/ ___________________/<C" - ??? only two first symbols of match at the and and some other text at the beginning.
    return ReplaceAction.Skip;

Thanks for your inquiry. This could occur because matched text consists of multiple runs. You can try using JoinRunsWithSameFormatting to resolve this issue. Please see the following link for more information.
Also I would like to suggest you using MailMerge functionality to fill your template with data. Please see the following link for more information.
Please let me know if you have any question regarding Aspose.Words, I will be glad to help you.
Best regards.