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

Free Support Forum - aspose.com

Find and replace forward is falling

Find and replace that is going forward does not work. I saw on some posts (on this forum) suggestion use false for isForward parameter. That does not work for me. I need to process document forward as I am adding some indexes and direction should be as that. Is there any work around for this ?

Code snippet :
Regex regex = new Regex(@"something", RegexOptions.IgnoreCase);
doc.Range.Replace(regex, new ReplaceEvaluatorAndIncrementCounters(), true);

this snippet fails with :
System.ArgumentOutOfRangeException was unhandled
HResult=-2146233086
Message=StartIndex cannot be less than zero.
Parameter name: startIndex
Source=mscorlib
ParamName=startIndex
StackTrace:
at System.String.Remove(Int32 startIndex, Int32 count)
at ? . (ReplacingArgs )
at ? . ()
at Aspose.Words.Range.Replace(Regex pattern, IReplacingCallback handler, Boolean isForward)
at CSharp.Programming_Documents.Find_and_Replace.FindAndHighlight.Run2() in f:\Programming\Aspose_Words_NET-master\Aspose_Words_NET-master\Examples\CSharp\Programming-Documents\Find-Replace\FindAndHighlight.cs:line 48
at CSharp.RunExamples.Main() in f:\Programming\Aspose_Words_NET-master\Aspose_Words_NET-master\Examples\CSharp\RunExamples.cs:line 101
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:


Thank you,
Rastko

Hi Rastko,

Can you please share your input document with complete code to reproduce the issue?

Best Regards,

Hi Muhammad,



Here are the code snippets and document in attachment. For description, I have in my document several occurrences of special tags that I want to replace with counters.
<NumberCounter> - number counter, starts from 1 and counts further
<LetterCounter> - starts from A, B, C, and goes further

I expect to process document top-down. And to have valid replacements. When I set true in Replace method I got exception. When I switch back to false, it works but I will have bottom up replacements that do not work for me.

private void ProcessTableOfContents(Aspose.Words.Document document)<o:p></o:p>

{

Regex regex = new Regex(@"<\*.+?(Counter)\*>", RegexOptions.IgnoreCase);

document.Range.Replace(regex, new ReplaceEvaluatorAndIncrementCounters(), true);

}


private class ReplaceEvaluatorAndIncrementCounters : IReplacingCallback

{

private int sectionNumberCounter = 1;

private int appendixLetterCounter;

private readonly string alphaLetters = "ABCDEFGHIJKLMNOPQRSTUVQXYZ";

ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)

{

switch (e.Match.ToString())

{

case "<*NumberCounter*>":

{

e.Replacement = string.Empty + sectionNumberCounter;

sectionNumberCounter++;

return ReplaceAction.Replace;

}

case "<*LetterCounter*>":

{

e.Replacement = string.Empty + alphaLetters[appendixLetterCounter % 26];

appendixLetterCounter++;

return ReplaceAction.Replace;

}

}

}

}


If you need more details, please let me know.

Thank you,

Rastko

Hi Rastko,

We are investigating the issue and will update you soon.

Best Regards,

Any update on this ?


Thanks

Hi Rastko,

We are able to reproduce the issue. It has been logged into our issue tracking system as WORDSNET-12530. We will keep you updated on this issue in this thread.

Best Regards,

Muhammad -

I too am running into this, and am interested in the fix. How do I subscribe to WORDSNET-12530 to be notified of a fix?

Thank you,
Sherri

Hi Sherri,


Thanks for being patient. Regarding WORDSNET-12530, our product team has completed the analysis of this issue and the root cause has been identified. Currently, they are on the final stage of reviewing/testing all code changes that were done in the scope of this issue. We will inform you via this thread as soon as your issue is resolved.

Best regards,

Hi Sherri,


Thanks for your inquiry. We have a good news i.e. our product team has resolved this issue (WORDSNET-12530) and they have planned to include the fix to your issue in next 15.11.0 release of Aspose.Words. We will inform you via this thread as soon as next release containing the fix to this issue is published in next few days.

Best regards,

The issues you have found earlier (filed as WORDSNET-12530) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
I confirm proper behavior with new version

Thank you !