Aspose::Words::Replacing::FindReplaceOptions::set_IgnoreFields method

FindReplaceOptions::set_IgnoreFields method

Sets a boolean value indicating either to ignore text inside fields. The default value is false.

void Aspose::Words::Replacing::FindReplaceOptions::set_IgnoreFields(bool value)

Remarks

This option affects whole field (all nodes between FieldStart and FieldEnd).

To ignore only field codes, please use corresponding option IgnoreFieldCodes.

Examples

Shows how to ignore text inside fields.

auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);

builder->Writeln(u"Hello world!");
builder->InsertField(u"QUOTE", u"Hello again!");

// We can use a "FindReplaceOptions" object to modify the find-and-replace process.
auto options = System::MakeObject<Aspose::Words::Replacing::FindReplaceOptions>();

// Set the "IgnoreFields" flag to "true" to get the find-and-replace
// operation to ignore text inside fields.
// Set the "IgnoreFields" flag to "false" to get the find-and-replace
// operation to also search for text inside fields.
options->set_IgnoreFields(ignoreTextInsideFields);

doc->get_Range()->Replace(u"Hello", u"Greetings", options);

ASSERT_EQ(doc->GetText().Trim(), ignoreTextInsideFields ? System::String(u"Greetings world!\r\u0013QUOTE\u0014Hello again!\u0015") : System::String(u"Greetings world!\r\u0013QUOTE\u0014Greetings again!\u0015"));

See Also