public ReplaceAction Replacing(ReplacingArgs args)
{
ArrayList runs = FindAndSplitMatchRuns(args);
// Create DocumentBuilder which is used to insert the field.
DocumentBuilder builder = new DocumentBuilder((Document)args.MatchNode.Document);
builder.MoveTo((Run)runs[runs.Count - 1]);
// Calculate the name of the field from the FieldType enumeration by removing the first instance of "Field" from the text.
// This works for almost all of the field types.
string fieldName = mFieldType.ToString().ToUpper().Substring(5);
// Insert the field into the document using the specified field type and the match text as the field name.
// If the fields you are inserting do not require this extra parameter then it can be removed from the string below.
builder.InsertField(string.Format("{0} {1}", fieldName, args.Match.Groups[0]));
// Now remove all runs in the sequence.
foreach (Run run in runs)
run.Remove();
// Signal to the replace engine to do nothing because we have already done all what we wanted.
return ReplaceAction.Skip;
}