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

Free Support Forum - aspose.com

Range.Replace gemerates compile time errors after upgrading to Aspose.Words for .NET 20.6

my project is no longer compiling, looks like Range.Replace has been changed.
i have a lot of code that uses this function that now wont compile with an invalid number of arguments error.
here are 2 examples, how do i fix this?
Dim regex As New Regex("<b>(.*?)</b>") 'used for bolding html tags in document
Try
doc.Range.Replace(regex, New ReplaceEvaluatorFindAndHighlight(), False)
Catch ex As Exception

    End Try
    Try
        doc.Range.Replace("<b>", "", False, False)
    Catch ex As Exception

    End Try

looking at this more, i use a piece of code i took from the developer articles where the ReplaceEvaluatorFindAndHighlight is a custom class copied below.
a recent words update has broken this. can you possibly provide a replacement sample.

Friend Class ReplaceEvaluatorFindAndHighlight
Implements IReplacingCallback
‘’’


‘’’ This method is called by the Aspose.Words find and replace engine for each match.
‘’’ This method highlights the match string, even if it spans multiple runs.
‘’’

Private Function IReplacingCallback_Replacing(ByVal e As ReplacingArgs) As ReplaceAction Implements IReplacingCallback.Replacing
’ This is a Run node that contains either the beginning or the complete match.
Dim currentNode As Node = e.MatchNode

    ' The first (and may be the only) run can contain text before the match, 
    ' in this case it is necessary to split the run.
    If e.MatchOffset > 0 Then
        currentNode = SplitRun(CType(currentNode, Run), e.MatchOffset)
    End If

    ' This array is used to store all nodes of the match for further highlighting.
    Dim runs As New ArrayList()

    ' Find all runs that contain parts of the match string.
    Dim remainingLength As Integer = e.Match.Value.Length
    Do While (remainingLength > 0) AndAlso (currentNode IsNot Nothing) AndAlso (currentNode.GetText().Length <= remainingLength)
        runs.Add(currentNode)
        remainingLength = remainingLength - currentNode.GetText().Length

        ' Select the next Run node. 
        ' Have to loop because there could be other nodes such as BookmarkStart etc.
        Do
            currentNode = currentNode.NextSibling
        Loop While (currentNode IsNot Nothing) AndAlso (currentNode.NodeType <> NodeType.Run)
    Loop

    ' Split the last run that contains the match if there is any text left.
    If (currentNode IsNot Nothing) AndAlso (remainingLength > 0) Then
        SplitRun(CType(currentNode, Run), remainingLength)
        runs.Add(currentNode)
    End If

    ' Now highlight all runs in the sequence.
    For Each run As Run In runs
        'run.Font.HighlightColor = Color.Yellow
        run.Text = run.Text.Replace(" < b > ", "")
        run.Text = run.Text.Replace("</b>", "")
        run.Font.Bold = True
    Next run

    ' Signal to the replace engine to do nothing because we have already done all what we wanted.
    Return ReplaceAction.Skip
End Function

@gavinduffy

Please check the code example of find and replace content in the following article.
Find and Replace

In the latest versions of Aspose.Words, the APIs related to find and replace contents are imported and changed. Please use FindReplaceOptions.ReplacingCallback property as shown below avoid the exception.

Moreover, please check the detail of Range.Replace overloads.

Dim doc As Document = New Document("input.docx")

Dim options As FindReplaceOptions = New FindReplaceOptions()
Dim callback As ReplaceEvaluatorFindAndHighlight = New ReplaceEvaluatorFindAndHighlight()

options.ReplacingCallback = callback

how do i apply this code?
your example does not connect the options variable with the doc object.
Dim regex As New Regex("<b>(.*?)</b>") 'used for bolding html tags in document
Try
'FAILS
doc.Range.Replace(regex, options)
'FAILS
doc.Range.Replace(regex, New ReplaceEvaluatorFindAndHighlight(), False)
Catch ex As Exception

    End Try

@gavinduffy

Please use Range.Replace Method (Regex, String, FindReplaceOptions) method. You need to use second parameter as empty string. There are some examples in API page. Please check them also.

Please read the Range.Replace methods as suggested in my previous post.

If you still face problem, please ZIP and attach your simplified project. We will modify the code and share it with you.