ReplaceRegex

Presentation.ReplaceRegex method

Replaces all matches of the regular expression with the specified string.

public void ReplaceRegex(Regex regex, string newText, IFindResultCallback callback)
ParameterTypeDescription
regexRegexThe regular expression Regex to get strings to replace.
newTextStringThe string to replace all occurrences of the strings to be replaced.
callbackIFindResultCallbackThe callback object for receiving search results IFindResultCallback.

Examples

The following code sample shows how to replace text using regular expression with the 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 '***'
	presentation.ReplaceRegex(regex, "***", null);
	presentation.Save("SomePresentation-out.pptx", SaveFormat.Pptx);
}

See Also