search/mag_sel search/close
Aspose::Words::BookmarkCollection Class Reference

A collection of Bookmark objects that represent the bookmarks in the specified range.

Examples

Shows how to add bookmarks and update their contents.

void CreateUpdateAndPrintBookmarks()
{
// Create a document with three bookmarks, then use a custom document visitor implementation to print their contents.
SharedPtr<Document> doc = CreateDocumentWithBookmarks(3);
SharedPtr<BookmarkCollection> bookmarks = doc->get_Range()->get_Bookmarks();
PrintAllBookmarkInfo(bookmarks);
// Bookmarks can be accessed in the bookmark collection by index or name, and their names can be updated.
bookmarks->idx_get(0)->set_Name(String::Format(u"{0}_NewName", bookmarks->idx_get(0)->get_Name()));
bookmarks->idx_get(u"MyBookmark_2")->set_Text(String::Format(u"Updated text contents of {0}", bookmarks->idx_get(1)->get_Name()));
// Print all bookmarks again to see updated values.
PrintAllBookmarkInfo(bookmarks);
}
static SharedPtr<Document> CreateDocumentWithBookmarks(int numberOfBookmarks)
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
for (int i = 1; i <= numberOfBookmarks; i++)
{
String bookmarkName = String(u"MyBookmark_") + i;
builder->Write(u"Text before bookmark.");
builder->StartBookmark(bookmarkName);
builder->Write(String::Format(u"Text inside {0}.", bookmarkName));
builder->EndBookmark(bookmarkName);
builder->Writeln(u"Text after bookmark.");
}
return doc;
}
static void PrintAllBookmarkInfo(SharedPtr<BookmarkCollection> bookmarks)
{
auto bookmarkVisitor = MakeObject<ExBookmarks::BookmarkInfoPrinter>();
// Get each bookmark in the collection to accept a visitor that will print its contents.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Bookmark>>> enumerator = bookmarks->GetEnumerator();
while (enumerator->MoveNext())
{
SharedPtr<Bookmark> currentBookmark = enumerator->get_Current();
if (currentBookmark != nullptr)
{
currentBookmark->get_BookmarkStart()->Accept(bookmarkVisitor);
currentBookmark->get_BookmarkEnd()->Accept(bookmarkVisitor);
std::cout << currentBookmark->get_BookmarkStart()->GetText() << std::endl;
}
}
}
}
class BookmarkInfoPrinter : public DocumentVisitor
{
public:
VisitorAction VisitBookmarkStart(SharedPtr<BookmarkStart> bookmarkStart) override
{
std::cout << "BookmarkStart name: \"" << bookmarkStart->get_Name() << "\", Contents: \"" << bookmarkStart->get_Bookmark()->get_Text() << "\""
<< std::endl;
}
VisitorAction VisitBookmarkEnd(SharedPtr<BookmarkEnd> bookmarkEnd) override
{
std::cout << "BookmarkEnd name: \"" << bookmarkEnd->get_Name() << "\"" << std::endl;
}
};

#include <Aspose.Words.Cpp/BookmarkCollection.h>

+ Inheritance diagram for Aspose::Words::BookmarkCollection:

Public Member Functions

void Clear ()
 Removes all bookmarks from this collection and from the document. More...
 
int32_t get_Count ()
 Returns the number of bookmarks in the collection. More...
 
SharedPtr< IEnumerator< SharedPtr< Bookmark > > > GetEnumerator () override
 Returns an enumerator object. More...
 
virtual const TypeInfoGetType () const override
 
SharedPtr< Bookmarkidx_get (int32_t index)
 Returns a bookmark at the specified index. More...
 
SharedPtr< Bookmarkidx_get (String bookmarkName)
 Returns a bookmark by name. More...
 
virtual bool Is (const TypeInfo &target) const override
 
void Remove (SharedPtr< Bookmark > bookmark)
 Removes the specified bookmark from the document. More...
 
void Remove (String bookmarkName)
 Removes a bookmark with the specified name. More...
 
void RemoveAt (int32_t index)
 Removes a bookmark at the specified index. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ Clear()

void Aspose::Words::BookmarkCollection::Clear ( )

Removes all bookmarks from this collection and from the document.

Examples

Shows how to remove bookmarks from a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert five bookmarks with text inside their boundaries.
for (int i = 1; i <= 5; i++)
{
String bookmarkName = String(u"MyBookmark_") + i;
builder->StartBookmark(bookmarkName);
builder->Write(String::Format(u"Text inside {0}.", bookmarkName));
builder->EndBookmark(bookmarkName);
builder->InsertBreak(BreakType::ParagraphBreak);
}
// This collection stores bookmarks.
SharedPtr<BookmarkCollection> bookmarks = doc->get_Range()->get_Bookmarks();
ASSERT_EQ(5, bookmarks->get_Count());
// There are several ways of removing bookmarks.
// 1 - Calling the bookmark's Remove method:
bookmarks->idx_get(u"MyBookmark_1")->Remove();
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_1"; }));
// 2 - Passing the bookmark to the collection's Remove method:
SharedPtr<Bookmark> bookmark = doc->get_Range()->get_Bookmarks()->idx_get(0);
doc->get_Range()->get_Bookmarks()->Remove(bookmark);
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_2"; }));
// 3 - Removing a bookmark from the collection by name:
doc->get_Range()->get_Bookmarks()->Remove(u"MyBookmark_3");
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_3"; }));
// 4 - Removing a bookmark at an index in the bookmark collection:
doc->get_Range()->get_Bookmarks()->RemoveAt(0);
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_4"; }));
// We can clear the entire bookmark collection.
bookmarks->Clear();
// The text that was inside the bookmarks is still present in the document.
ASSERT_EQ(0, bookmarks->get_Count());
ASSERT_EQ(String(u"Text inside MyBookmark_1.\r") + u"Text inside MyBookmark_2.\r" + u"Text inside MyBookmark_3.\r" + u"Text inside MyBookmark_4.\r" +
u"Text inside MyBookmark_5.",
doc->GetText().Trim());

◆ get_Count()

int32_t Aspose::Words::BookmarkCollection::get_Count ( )

Returns the number of bookmarks in the collection.

Examples

Shows how to remove bookmarks from a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert five bookmarks with text inside their boundaries.
for (int i = 1; i <= 5; i++)
{
String bookmarkName = String(u"MyBookmark_") + i;
builder->StartBookmark(bookmarkName);
builder->Write(String::Format(u"Text inside {0}.", bookmarkName));
builder->EndBookmark(bookmarkName);
builder->InsertBreak(BreakType::ParagraphBreak);
}
// This collection stores bookmarks.
SharedPtr<BookmarkCollection> bookmarks = doc->get_Range()->get_Bookmarks();
ASSERT_EQ(5, bookmarks->get_Count());
// There are several ways of removing bookmarks.
// 1 - Calling the bookmark's Remove method:
bookmarks->idx_get(u"MyBookmark_1")->Remove();
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_1"; }));
// 2 - Passing the bookmark to the collection's Remove method:
SharedPtr<Bookmark> bookmark = doc->get_Range()->get_Bookmarks()->idx_get(0);
doc->get_Range()->get_Bookmarks()->Remove(bookmark);
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_2"; }));
// 3 - Removing a bookmark from the collection by name:
doc->get_Range()->get_Bookmarks()->Remove(u"MyBookmark_3");
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_3"; }));
// 4 - Removing a bookmark at an index in the bookmark collection:
doc->get_Range()->get_Bookmarks()->RemoveAt(0);
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_4"; }));
// We can clear the entire bookmark collection.
bookmarks->Clear();
// The text that was inside the bookmarks is still present in the document.
ASSERT_EQ(0, bookmarks->get_Count());
ASSERT_EQ(String(u"Text inside MyBookmark_1.\r") + u"Text inside MyBookmark_2.\r" + u"Text inside MyBookmark_3.\r" + u"Text inside MyBookmark_4.\r" +
u"Text inside MyBookmark_5.",
doc->GetText().Trim());

◆ GetEnumerator()

System::SharedPtr<System::Collections::Generic::IEnumerator<System::SharedPtr<Aspose::Words::Bookmark> > > Aspose::Words::BookmarkCollection::GetEnumerator ( )
override

Returns an enumerator object.

Examples

Shows how to add bookmarks and update their contents.

void CreateUpdateAndPrintBookmarks()
{
// Create a document with three bookmarks, then use a custom document visitor implementation to print their contents.
SharedPtr<Document> doc = CreateDocumentWithBookmarks(3);
SharedPtr<BookmarkCollection> bookmarks = doc->get_Range()->get_Bookmarks();
PrintAllBookmarkInfo(bookmarks);
// Bookmarks can be accessed in the bookmark collection by index or name, and their names can be updated.
bookmarks->idx_get(0)->set_Name(String::Format(u"{0}_NewName", bookmarks->idx_get(0)->get_Name()));
bookmarks->idx_get(u"MyBookmark_2")->set_Text(String::Format(u"Updated text contents of {0}", bookmarks->idx_get(1)->get_Name()));
// Print all bookmarks again to see updated values.
PrintAllBookmarkInfo(bookmarks);
}
static SharedPtr<Document> CreateDocumentWithBookmarks(int numberOfBookmarks)
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
for (int i = 1; i <= numberOfBookmarks; i++)
{
String bookmarkName = String(u"MyBookmark_") + i;
builder->Write(u"Text before bookmark.");
builder->StartBookmark(bookmarkName);
builder->Write(String::Format(u"Text inside {0}.", bookmarkName));
builder->EndBookmark(bookmarkName);
builder->Writeln(u"Text after bookmark.");
}
return doc;
}
static void PrintAllBookmarkInfo(SharedPtr<BookmarkCollection> bookmarks)
{
auto bookmarkVisitor = MakeObject<ExBookmarks::BookmarkInfoPrinter>();
// Get each bookmark in the collection to accept a visitor that will print its contents.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Bookmark>>> enumerator = bookmarks->GetEnumerator();
while (enumerator->MoveNext())
{
SharedPtr<Bookmark> currentBookmark = enumerator->get_Current();
if (currentBookmark != nullptr)
{
currentBookmark->get_BookmarkStart()->Accept(bookmarkVisitor);
currentBookmark->get_BookmarkEnd()->Accept(bookmarkVisitor);
std::cout << currentBookmark->get_BookmarkStart()->GetText() << std::endl;
}
}
}
}
class BookmarkInfoPrinter : public DocumentVisitor
{
public:
VisitorAction VisitBookmarkStart(SharedPtr<BookmarkStart> bookmarkStart) override
{
std::cout << "BookmarkStart name: \"" << bookmarkStart->get_Name() << "\", Contents: \"" << bookmarkStart->get_Bookmark()->get_Text() << "\""
<< std::endl;
}
VisitorAction VisitBookmarkEnd(SharedPtr<BookmarkEnd> bookmarkEnd) override
{
std::cout << "BookmarkEnd name: \"" << bookmarkEnd->get_Name() << "\"" << std::endl;
}
};

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::BookmarkCollection::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ idx_get() [1/2]

System::SharedPtr<Aspose::Words::Bookmark> Aspose::Words::BookmarkCollection::idx_get ( int32_t  index)

Returns a bookmark at the specified index.

The index is zero-based.

Negative indexes are allowed and indicate access from the back of the collection. For example -1 means the last item, -2 means the second before last and so on.

If index is greater than or equal to the number of items in the list, this returns a null reference.

If index is negative and its absolute value is greater than the number of items in the list, this returns a null reference.

Parameters
indexAn index into the collection.
Examples

Shows how to add bookmarks and update their contents.

void CreateUpdateAndPrintBookmarks()
{
// Create a document with three bookmarks, then use a custom document visitor implementation to print their contents.
SharedPtr<Document> doc = CreateDocumentWithBookmarks(3);
SharedPtr<BookmarkCollection> bookmarks = doc->get_Range()->get_Bookmarks();
PrintAllBookmarkInfo(bookmarks);
// Bookmarks can be accessed in the bookmark collection by index or name, and their names can be updated.
bookmarks->idx_get(0)->set_Name(String::Format(u"{0}_NewName", bookmarks->idx_get(0)->get_Name()));
bookmarks->idx_get(u"MyBookmark_2")->set_Text(String::Format(u"Updated text contents of {0}", bookmarks->idx_get(1)->get_Name()));
// Print all bookmarks again to see updated values.
PrintAllBookmarkInfo(bookmarks);
}
static SharedPtr<Document> CreateDocumentWithBookmarks(int numberOfBookmarks)
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
for (int i = 1; i <= numberOfBookmarks; i++)
{
String bookmarkName = String(u"MyBookmark_") + i;
builder->Write(u"Text before bookmark.");
builder->StartBookmark(bookmarkName);
builder->Write(String::Format(u"Text inside {0}.", bookmarkName));
builder->EndBookmark(bookmarkName);
builder->Writeln(u"Text after bookmark.");
}
return doc;
}
static void PrintAllBookmarkInfo(SharedPtr<BookmarkCollection> bookmarks)
{
auto bookmarkVisitor = MakeObject<ExBookmarks::BookmarkInfoPrinter>();
// Get each bookmark in the collection to accept a visitor that will print its contents.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Bookmark>>> enumerator = bookmarks->GetEnumerator();
while (enumerator->MoveNext())
{
SharedPtr<Bookmark> currentBookmark = enumerator->get_Current();
if (currentBookmark != nullptr)
{
currentBookmark->get_BookmarkStart()->Accept(bookmarkVisitor);
currentBookmark->get_BookmarkEnd()->Accept(bookmarkVisitor);
std::cout << currentBookmark->get_BookmarkStart()->GetText() << std::endl;
}
}
}
}
class BookmarkInfoPrinter : public DocumentVisitor
{
public:
VisitorAction VisitBookmarkStart(SharedPtr<BookmarkStart> bookmarkStart) override
{
std::cout << "BookmarkStart name: \"" << bookmarkStart->get_Name() << "\", Contents: \"" << bookmarkStart->get_Bookmark()->get_Text() << "\""
<< std::endl;
}
VisitorAction VisitBookmarkEnd(SharedPtr<BookmarkEnd> bookmarkEnd) override
{
std::cout << "BookmarkEnd name: \"" << bookmarkEnd->get_Name() << "\"" << std::endl;
}
};

◆ idx_get() [2/2]

System::SharedPtr<Aspose::Words::Bookmark> Aspose::Words::BookmarkCollection::idx_get ( System::String  bookmarkName)

Returns a bookmark by name.

Returns null if the bookmark with the specified name cannot be found.

Parameters
bookmarkNameCase-insensitive name of the bookmark.
Examples

Shows how to add bookmarks and update their contents.

void CreateUpdateAndPrintBookmarks()
{
// Create a document with three bookmarks, then use a custom document visitor implementation to print their contents.
SharedPtr<Document> doc = CreateDocumentWithBookmarks(3);
SharedPtr<BookmarkCollection> bookmarks = doc->get_Range()->get_Bookmarks();
PrintAllBookmarkInfo(bookmarks);
// Bookmarks can be accessed in the bookmark collection by index or name, and their names can be updated.
bookmarks->idx_get(0)->set_Name(String::Format(u"{0}_NewName", bookmarks->idx_get(0)->get_Name()));
bookmarks->idx_get(u"MyBookmark_2")->set_Text(String::Format(u"Updated text contents of {0}", bookmarks->idx_get(1)->get_Name()));
// Print all bookmarks again to see updated values.
PrintAllBookmarkInfo(bookmarks);
}
static SharedPtr<Document> CreateDocumentWithBookmarks(int numberOfBookmarks)
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
for (int i = 1; i <= numberOfBookmarks; i++)
{
String bookmarkName = String(u"MyBookmark_") + i;
builder->Write(u"Text before bookmark.");
builder->StartBookmark(bookmarkName);
builder->Write(String::Format(u"Text inside {0}.", bookmarkName));
builder->EndBookmark(bookmarkName);
builder->Writeln(u"Text after bookmark.");
}
return doc;
}
static void PrintAllBookmarkInfo(SharedPtr<BookmarkCollection> bookmarks)
{
auto bookmarkVisitor = MakeObject<ExBookmarks::BookmarkInfoPrinter>();
// Get each bookmark in the collection to accept a visitor that will print its contents.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Bookmark>>> enumerator = bookmarks->GetEnumerator();
while (enumerator->MoveNext())
{
SharedPtr<Bookmark> currentBookmark = enumerator->get_Current();
if (currentBookmark != nullptr)
{
currentBookmark->get_BookmarkStart()->Accept(bookmarkVisitor);
currentBookmark->get_BookmarkEnd()->Accept(bookmarkVisitor);
std::cout << currentBookmark->get_BookmarkStart()->GetText() << std::endl;
}
}
}
}
class BookmarkInfoPrinter : public DocumentVisitor
{
public:
VisitorAction VisitBookmarkStart(SharedPtr<BookmarkStart> bookmarkStart) override
{
std::cout << "BookmarkStart name: \"" << bookmarkStart->get_Name() << "\", Contents: \"" << bookmarkStart->get_Bookmark()->get_Text() << "\""
<< std::endl;
}
VisitorAction VisitBookmarkEnd(SharedPtr<BookmarkEnd> bookmarkEnd) override
{
std::cout << "BookmarkEnd name: \"" << bookmarkEnd->get_Name() << "\"" << std::endl;
}
};

◆ Is()

virtual bool Aspose::Words::BookmarkCollection::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from System::Object.

◆ Remove() [1/2]

void Aspose::Words::BookmarkCollection::Remove ( System::SharedPtr< Aspose::Words::Bookmark bookmark)

Removes the specified bookmark from the document.

Parameters
bookmarkThe bookmark to remove.
Examples

Shows how to remove bookmarks from a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert five bookmarks with text inside their boundaries.
for (int i = 1; i <= 5; i++)
{
String bookmarkName = String(u"MyBookmark_") + i;
builder->StartBookmark(bookmarkName);
builder->Write(String::Format(u"Text inside {0}.", bookmarkName));
builder->EndBookmark(bookmarkName);
builder->InsertBreak(BreakType::ParagraphBreak);
}
// This collection stores bookmarks.
SharedPtr<BookmarkCollection> bookmarks = doc->get_Range()->get_Bookmarks();
ASSERT_EQ(5, bookmarks->get_Count());
// There are several ways of removing bookmarks.
// 1 - Calling the bookmark's Remove method:
bookmarks->idx_get(u"MyBookmark_1")->Remove();
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_1"; }));
// 2 - Passing the bookmark to the collection's Remove method:
SharedPtr<Bookmark> bookmark = doc->get_Range()->get_Bookmarks()->idx_get(0);
doc->get_Range()->get_Bookmarks()->Remove(bookmark);
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_2"; }));
// 3 - Removing a bookmark from the collection by name:
doc->get_Range()->get_Bookmarks()->Remove(u"MyBookmark_3");
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_3"; }));
// 4 - Removing a bookmark at an index in the bookmark collection:
doc->get_Range()->get_Bookmarks()->RemoveAt(0);
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_4"; }));
// We can clear the entire bookmark collection.
bookmarks->Clear();
// The text that was inside the bookmarks is still present in the document.
ASSERT_EQ(0, bookmarks->get_Count());
ASSERT_EQ(String(u"Text inside MyBookmark_1.\r") + u"Text inside MyBookmark_2.\r" + u"Text inside MyBookmark_3.\r" + u"Text inside MyBookmark_4.\r" +
u"Text inside MyBookmark_5.",
doc->GetText().Trim());

◆ Remove() [2/2]

void Aspose::Words::BookmarkCollection::Remove ( System::String  bookmarkName)

Removes a bookmark with the specified name.

Parameters
bookmarkNameThe case-insensitive name of the bookmark to remove.
Examples

Shows how to remove bookmarks from a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert five bookmarks with text inside their boundaries.
for (int i = 1; i <= 5; i++)
{
String bookmarkName = String(u"MyBookmark_") + i;
builder->StartBookmark(bookmarkName);
builder->Write(String::Format(u"Text inside {0}.", bookmarkName));
builder->EndBookmark(bookmarkName);
builder->InsertBreak(BreakType::ParagraphBreak);
}
// This collection stores bookmarks.
SharedPtr<BookmarkCollection> bookmarks = doc->get_Range()->get_Bookmarks();
ASSERT_EQ(5, bookmarks->get_Count());
// There are several ways of removing bookmarks.
// 1 - Calling the bookmark's Remove method:
bookmarks->idx_get(u"MyBookmark_1")->Remove();
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_1"; }));
// 2 - Passing the bookmark to the collection's Remove method:
SharedPtr<Bookmark> bookmark = doc->get_Range()->get_Bookmarks()->idx_get(0);
doc->get_Range()->get_Bookmarks()->Remove(bookmark);
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_2"; }));
// 3 - Removing a bookmark from the collection by name:
doc->get_Range()->get_Bookmarks()->Remove(u"MyBookmark_3");
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_3"; }));
// 4 - Removing a bookmark at an index in the bookmark collection:
doc->get_Range()->get_Bookmarks()->RemoveAt(0);
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_4"; }));
// We can clear the entire bookmark collection.
bookmarks->Clear();
// The text that was inside the bookmarks is still present in the document.
ASSERT_EQ(0, bookmarks->get_Count());
ASSERT_EQ(String(u"Text inside MyBookmark_1.\r") + u"Text inside MyBookmark_2.\r" + u"Text inside MyBookmark_3.\r" + u"Text inside MyBookmark_4.\r" +
u"Text inside MyBookmark_5.",
doc->GetText().Trim());

◆ RemoveAt()

void Aspose::Words::BookmarkCollection::RemoveAt ( int32_t  index)

Removes a bookmark at the specified index.

Parameters
indexThe zero-based index of the bookmark to remove.
Examples

Shows how to remove bookmarks from a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert five bookmarks with text inside their boundaries.
for (int i = 1; i <= 5; i++)
{
String bookmarkName = String(u"MyBookmark_") + i;
builder->StartBookmark(bookmarkName);
builder->Write(String::Format(u"Text inside {0}.", bookmarkName));
builder->EndBookmark(bookmarkName);
builder->InsertBreak(BreakType::ParagraphBreak);
}
// This collection stores bookmarks.
SharedPtr<BookmarkCollection> bookmarks = doc->get_Range()->get_Bookmarks();
ASSERT_EQ(5, bookmarks->get_Count());
// There are several ways of removing bookmarks.
// 1 - Calling the bookmark's Remove method:
bookmarks->idx_get(u"MyBookmark_1")->Remove();
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_1"; }));
// 2 - Passing the bookmark to the collection's Remove method:
SharedPtr<Bookmark> bookmark = doc->get_Range()->get_Bookmarks()->idx_get(0);
doc->get_Range()->get_Bookmarks()->Remove(bookmark);
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_2"; }));
// 3 - Removing a bookmark from the collection by name:
doc->get_Range()->get_Bookmarks()->Remove(u"MyBookmark_3");
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_3"; }));
// 4 - Removing a bookmark at an index in the bookmark collection:
doc->get_Range()->get_Bookmarks()->RemoveAt(0);
ASSERT_FALSE(bookmarks->LINQ_Any([](SharedPtr<Bookmark> b) { return b->get_Name() == u"MyBookmark_4"; }));
// We can clear the entire bookmark collection.
bookmarks->Clear();
// The text that was inside the bookmarks is still present in the document.
ASSERT_EQ(0, bookmarks->get_Count());
ASSERT_EQ(String(u"Text inside MyBookmark_1.\r") + u"Text inside MyBookmark_2.\r" + u"Text inside MyBookmark_3.\r" + u"Text inside MyBookmark_4.\r" +
u"Text inside MyBookmark_5.",
doc->GetText().Trim());

◆ Type()

static const System::TypeInfo& Aspose::Words::BookmarkCollection::Type ( )
static