Free Support Forum - aspose.com

Text between two bookmarks

Hello



It’s possibe to select an replace text between two Bookmarks (BMStart, BMEnd) on an existing document?



[BMStarart]Text Text Text[BMEnd]



Regards

Hi Stefan,


Thanks for your inquiry. Sure, you can get or set the text enclosed in the bookmark using Bookmark.Text property. The following example shows how to get or set bookmark name and text.

Document doc = new Document(MyDir + “Bookmark.doc”);

// Use the indexer of the Bookmarks collection to obtain the desired bookmark.
Bookmark bookmark = doc.Range.Bookmarks[“MyBookmark”];

// Get the name and text of the bookmark.
string name = bookmark.Name;
string text = bookmark.Text;

// Set the name and text of the bookmark.
bookmark.Name = “RenamedBookmark”;
bookmark.Text = “This is a new bookmarked text.”;


Hope, this helps.

Best regards,

Hi

Thanks for your answer, but I think, it’s not exactly what I mean.



Situation:

An existing Word-Document has two Bookmarks - a start-Bookmark and an end-Bookmark. There is text between the Bookmarks. Now I have to get the Text between this two Bookmarks and replace it.



|This is Text|

^________^

| ________ Bookmark-End

Bookmark-Start



Here a sample how I used in in Office:



docword.Bookmarks.Item(“BMStart”).Select()

pos = docword.Bookmarks.Item(“BMStart”).Start

docword.Bookmarks.Item(“BMEnd”).Select()

pos2 = docword.Bookmarks.Item(“BMEnd”).Start

objword.Selection.SetRange(Start:=pos, End:=pos2)

objword.Selection.TypeText(“New Text”)





Kind regards

Hi Stefan,


Thanks for the details. Please refer to the following section of documentation:
http://www.aspose.com/docs/display/wordsnet/How+to++Extract+Selected+Content+Between+Nodes+in+a+Document

I hope, this helps.

Best regards,