Replace with bookmark

hi,everybody
I have a problem
abcd[here is a bookmark named bm_1]ef
I want find this bookmark and insert some content
like
abcdcontentef

Bookmark bm = myDoc.Range.Bookmarks["bm_1"];
builder.MoveTo(bm.BookmarkStart.ParentNode);

builder.Underline = Underline.Single;
builder.Writeln("content");
bm.Text = string.Empty;
bm.Remove();

with this code the result is abcdefcontent
how I to do it?
thanks

Hi,
Thanks for your inquiry. Please check following code snippet for replacing bookmark. Hopefully it will serve the purpose. Please use MoveToBookmark() method for moving cursor to specific bookmark.

Bookmark bm = doc.Range.Bookmarks["bm_1"];
builder.MoveToBookmark("bm_1",true,ture);
builder.Underline = Underline.Single; 
builder.Write("content");
bm.Text = string.Empty;
bm.Remove();

Please feel free to contact us for any further assistance.
Best Regards,

Hi,
there are some wrong with the code you provide

builder.Write("content");
bm.Text = string.Empty;

I try this code is correct and the text “aaaaa” is not write to word

builder.Write("aaaaa");
bm.Text = "content";

Hi,
Thanks for your feedback. It’s perfect that you managed to get your desired results.
As a reference, please find complete code and output document.

Document doc = new Document(MyDir+"bookmarktest.doc");
DocumentBuilder builder= new DocumentBuilder(doc);
Bookmark bm = doc.Range.Bookmarks["bm_1"];
builder.MoveToBookmark("bm_1",true,false);
builder.Underline = Underline.Single; 
// documentbuilder writes underlined text in start of bookmark
builder.Write("hello");
// set text of bookmark. set to string.Empty for removing bookmark text.
bm.Text = "content";
// bm.Text = string.Empty;
// To remove bookmark
// bm.Remove();
doc.Save(MyDir+"out.doc");

Please feel free to contact us for any further assistance.
Best Regards,

Thank you very much

Hi,
It’s good to hear that you have achieved your desired results. Please let us know for any further query. We will be more than happy to help you…
Best Regards,