Hello
Thank you for additional information. I can suggest you two variants:
First one: check if a bookmark contains brackets:
Document doc = new Document(“C:\Temp\BeforeAspose2.doc”);
foreach (Bookmark bk in doc.Range.Bookmarks)
{
if (bk.Text.Contains("["))
bk.Text = bk.Text.Replace("[", " ");
if (bk.Text.Contains("]"))
bk.Text = bk.Text.Replace("]", " ");
}
doc.Save(“C:\Temp\out.doc”);
Second one: try using the following code:
foreach (Bookmark bookmark in doc.Range.Bookmarks)
{
Node curNode = bookmark.BookmarkStart;
while (curNode != null && !curNode.Equals(bookmark.BookmarkEnd))
{
//Move to next node
Node nextNode = curNode.NextPreOrder(doc);
//Check whether current contains end node
if (curNode.IsComposite)
{
if (!((CompositeNode)curNode).GetChildNodes(NodeType.Any, true).Contains(bookmark.BookmarkEnd) &&
!((CompositeNode)curNode).GetChildNodes(NodeType.Any, true).Contains(bookmark.BookmarkStart))
{
nextNode = curNode.NextSibling;
curNode.Range.Replace(new Regex("[\[\]]"), " ");
}
}
else
{
curNode.Range.Replace(new Regex("[\[\]]"), " ");
}
curNode = nextNode;
}
}
Best regards,