ReplaceRegex()

TextFrame::ReplaceRegex(System::SharedPtr<System::Text::RegularExpressions::Regex>, System::String, System::SharedPtr<IFindResultCallback>) method

Replaces all matches of regular expression with specified string.

void Aspose::Slides::TextFrame::ReplaceRegex(System::SharedPtr<System::Text::RegularExpressions::Regex> regex, System::String newText, System::SharedPtr<IFindResultCallback> callback) override

Arguments

ParameterTypeDescription
regexSystem::SharedPtr<System::Text::RegularExpressions::Regex>The regular expression System::Text::RegularExpressions::Regex to get strings to be replaced.
newTextSystem::StringThe string to replace all occurrences of strings to be replaced.
callbackSystem::SharedPtr<IFindResultCallback>Callback object for saving replacement operation result IFindResultCallback.

Remarks

The following sample code shows how to replace text using regular expression with specified string.

auto presentation = System::MakeObject<Presentation>(u"SomePresentation.pptx");
auto shape = System::ExplicitCast<AutoShape>(presentation->get_Slide(0)->get_Shape(0));

auto regex = System::MakeObject<System::Text::RegularExpressions::Regex>(u"\\b[^\\s]{10,}\\b");

// Replace all words with 10 or more characters with '<em><strong>'
shape->get_TextFrame()->ReplaceRegex(regex, u"</strong></em>", nullptr);
presentation->Save(u"SomePresentation-out.pptx", SaveFormat::Pptx);

See Also