ReplaceRegex

TextFrame.ReplaceRegex method

用指定字符串替换正则表达式的所有匹配项。

public void ReplaceRegex(Regex regex, string newText, IFindResultCallback callback)
参数类型描述
regexRegex获取要被替换字符串的正则表达式 Regex。
newTextString用于替换所有被替换字符串的字符串。
callbackIFindResultCallback用于保存替换操作结果的回调对象 IFindResultCallback

示例

以下示例代码演示了如何使用正则表达式和指定字符串替换文本。

[C#]
using (Presentation presentation = new Presentation("SomePresentation.pptx")){
	Regex regex = new Regex(@"\b[^\s]{10,}\b");
	// 用 '***' 替换所有10个或更多字符的单词
	((AutoShape)presentation.Slides[0].Shapes[0]).TextFrame.ReplaceRegex(regex, "***", null);
	presentation.Save("SomePresentation-out.pptx", SaveFormat.Pptx);
}

另请参阅