ReplaceRegex

TextFrame.ReplaceRegex method

Replaces all matches of regular expression with specified string.

public void ReplaceRegex(Regex regex, string newText, IFindResultCallback callback)
ParameterTypeDescription
regexRegexThe regular expression Regex to get strings to be replaced.
newTextStringThe string to replace all occurrences of strings to be replaced.
callbackIFindResultCallbackCallback object for saving replacement operation result IFindResultCallback.

Examples

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

[C#]
using (Presentation presentation = new Presentation("SomePresentation.pptx")){
	Regex regex = new Regex(@"\b[^\s]{10,}\b");
	// Replace all words with 10 or more characters with '***'
	((AutoShape)presentation.Slides[0].Shapes[0]).TextFrame.ReplaceRegex(regex, "***", null);
	presentation.Save("SomePresentation-out.pptx", SaveFormat.Pptx);
}

See Also