ReplaceText

TextFrame.ReplaceText method

Replaces all occurrences of the specified text with another specified text.

public void ReplaceText(string oldText, string newText, ITextSearchOptions options, 
    IFindResultCallback callback)
ParameterTypeDescription
oldTextStringThe string to be replaced.
newTextStringThe string to replace all occurrences of oldText.
optionsITextSearchOptionsText search options ITextSearchOptions.
callbackIFindResultCallbackCallback object for saving replacement operation result IFindResultCallback.

Examples

The following sample code shows how to replace one speified string with another speified string.

[C#]
using (Presentation presentation = new Presentation("SomePresentation.pptx")){
	// Replace all separate 'the' occurrences with '***'
	((AutoShape)presentation.Slides[0].Shapes[0]).TextFrame.ReplaceText("the", "***", new TextSearchOptions()
	{ WholeWordsOnly = true }, null);
	presentation.Save("SomePresentation-out2.pptx", SaveFormat.Pptx);
}

See Also