Hi
Thanks for your request. e.MatchNode is Run that can contain other text than MatchValue. Please try using the following code:
public ReplaceAction InsertDocEvaluator(object sender, ReplaceEvaluatorArgs e)
{
//Get MatchNode
Run run1 = (Run)e.MatchNode;
//Create Run
Run run2 = new Run(e.MatchNode.Document, string.Empty);
//Get index of match value
int index = run1.Text.IndexOf(e.Match.Value);
if (index > 0)
{
//Split text in match node
run2.Text = string.IsNullOrEmpty(run1.Text.Substring(0, index)) ? " " : run1.Text.Substring(0, index);
run1.Text = string.IsNullOrEmpty(run1.Text.Substring(index + e.Match.Value.Length)) ? " " : run1.Text.Substring(index + e.Match.Value.Length);
}
else
{
run2.Text = " ";
run1.Text = string.IsNullOrEmpty(run1.Text.Substring(e.Match.Value.Length)) ? " " : run1.Text.Substring(e.Match.Value.Length);
}
run1.ParentParagraph.InsertBefore(run2, run1);
DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document);
//Move to run1
builder.MoveTo(run1);
string mNodeText = "BM" + (new Random()).Next(1000, 100000);
builder.StartBookmark(mNodeText);
builder.EndBookmark(mNodeText);
try
{
InsertDocumentAtBookamrk(mNodeText, builder.Document, m_doc);
}
catch(Exception)
{
}
return (ReplaceAction.Skip);
}
I hope this could help you.
Best regards.
Alexey Noskov
Developer/Technical Support
Aspose Auckland Team