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

Free Support Forum - aspose.com

Search not always working properly

I have a whole lot of documents where the are a kind of formfields.
These fields all start and end with @ and everything (including @) is double underlined.

I implemented a search and replace routine but Aspose doesn’t find the text properly.
Attached is a test document that I use for searching. When you start the app the first text that is found is ‘@Kund’, the second one is ‘_Briefkopf!@’ where all this is a single text in the input document.
Am I doing something wrong or is this a bug?

Thomas

Hi Thomas,


Thanks for your inquiry. Please note that the matched text can be in one or multiple Run nodes. In your case, we suggest you please use following modified code example to get the desired output. Hope this helps you.

Sub Main()<o:p></o:p>

Dim filename As String = ".\anfangstext.doc"

Dim doc As New Aspose.Words.Document(filename)

doc.JoinRunsWithSameFormatting()

FillWordFields(doc)

doc.Save(".\AfterSearch.doc")

Console.WriteLine("Search/Replace finished")

Console.WriteLine("Output saved in .\AfterSearch.doc")

Console.ReadKey()

End Sub

Private Sub FillWordFields(doc As Aspose.Words.Document)

Dim options As New Replacing.FindReplaceOptions

options.ReplacingCallback = New MyReplaceEvaluator

AddHandler CType(options.ReplacingCallback, MyReplaceEvaluator).FillReplace, AddressOf DoFillReplace

doc.Range.Replace(New Text.RegularExpressions.Regex("(?<=@)(.*?)(?=@)"), "", options)

End Sub

Private Sub DoFillReplace(Textrun As Run, Formfield As String)

Dim newvalue As String = "Newvalue:" + Textrun.Text.Replace("@", "")

Textrun.Font.Underline = Underline.None

Textrun.Text = newvalue

End Sub

Works like a charm. Thanks

Thomas

Hi Thomas,


Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.