Hello Aspose Team,
I am new to Aspose words, I want to remove a specific para or lines for example.
Updated Question:
Answer: <map><m x1="232" x2="384" y1="116" y2="140" ss="0" a="0" /><m x1="319" x2="479" y1="210" y2="231" ss="0" a="0" /><m x1="246" x2="497" y1="363" y2="382" ss="0" a="0" /></map>
I want to remove all paragraphs with map codes from document. Just want to keep Answer: text.
I tried to remove using this code
doc.Range.Replace(new Regex(Regex.Escape("<map>")), new RemoveAddressLine(), false);
public class RemoveAddressLine : IReplacingCallback
{
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
{
DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document as Document);
Node currentNode = e.MatchNode;
builder.MoveTo(currentNode);
builder.CurrentParagraph.Remove();
return ReplaceAction.Replace;
}
}
but it also removed Answer: but I want to keep it.
I also tried to use Bookmarks
FindReplaceOptions replaceOptions = new FindReplaceOptions();
replaceOptions.ReplacingCallback = new BookMarkStartLine();
doc.Range.Replace(new Regex("<map>"), "", replaceOptions);
replaceOptions.ReplacingCallback = new BookMarkEndLine();
doc.Range.Replace(new Regex("</map>"), "", replaceOptions);
doc.Range.Bookmarks.Clear();
public class BookMarkStartLine : IReplacingCallback
{
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
{
DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document as Document);
Node currentNode = e.MatchNode;
builder.MoveTo(currentNode);
builder.StartBookmark("bookmark_start");
return ReplaceAction.Replace;
}
}
public class BookMarkEndLine : IReplacingCallback
{
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
{
DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document as Document);
Node currentNode = e.MatchNode;
builder.MoveTo(currentNode);
builder.EndBookmark("bookmark_end");
return ReplaceAction.Replace;
}
}
but it’s throwing an exception that can’t find bookmark_start in the docuement, Please help
Thanks in advance
Arbaz