ReplaceRegex

ITextFrame.ReplaceRegex 方法

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

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);
}

另请参见