Aspose::Words::Fields::FieldCollection::Remove method
Contents
[
Hide
]FieldCollection::Remove method
Removes the specified field from this collection and from the document.
void Aspose::Words::Fields::FieldCollection::Remove(const System::SharedPtr<Aspose::Words::Fields::Field> & field)
| Parameter | Type | Description |
|---|---|---|
| field | const System::SharedPtr<Aspose::Words::Fields::Field> & | A field to remove. |
Examples
Shows how to remove fields from a field collection.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
builder->InsertField(u" DATE \\@ \"dddd, d MMMM yyyy\" ");
builder->InsertField(u" TIME ");
builder->InsertField(u" REVNUM ");
builder->InsertField(u" AUTHOR \"John Doe\" ");
builder->InsertField(u" SUBJECT \"My Subject\" ");
builder->InsertField(u" QUOTE \"Hello world!\" ");
doc->UpdateFields();
System::SharedPtr<Aspose::Words::Fields::FieldCollection> fields = doc->get_Range()->get_Fields();
ASSERT_EQ(fields->get_Count(), 6);
// Below are four ways of removing fields from a field collection.
// 1 - Get a field to remove itself:
fields->idx_get(0)->Remove();
ASSERT_EQ(fields->get_Count(), 5);
// 2 - Get the collection to remove a field that we pass to its removal method:
System::SharedPtr<Aspose::Words::Fields::Field> lastField = fields->idx_get(3);
fields->Remove(lastField);
ASSERT_EQ(fields->get_Count(), 4);
// 3 - Remove a field from a collection at an index:
fields->RemoveAt(2);
ASSERT_EQ(fields->get_Count(), 3);
// 4 - Remove all the fields from the collection at once:
fields->Clear();
ASSERT_EQ(fields->get_Count(), 0);
See Also
- Class FieldCollection
- Namespace Aspose::Words::Fields
- Library Aspose.Words for C++