HighlightRegex

TextFrame.HighlightRegex 方法

使用指定颜色突出显示正则表达式的所有匹配项。

public void HighlightRegex(Regex regex, Color highlightColor, IFindResultCallback callback)
参数类型描述
regexRegex要高亮显示的字符串的正则表达式 Regex。
highlightColorColor用于高亮显示文本的颜色。
callbackIFindResultCallback接收搜索结果的回调对象 IFindResultCallback

示例

以下代码示例演示如何使用正则表达式在 TextFrame 中高亮显示文本。

[C#]
using (Presentation presentation = new Presentation("SomePresentation.pptx"))
{
	Regex regex = new Regex(@"\b[^\s]{10,}\b");
	// 高亮显示所有长度为10个或更多字符的单词
	((AutoShape)presentation.Slides[0].Shapes[0]).TextFrame.HighlightRegex(regex, Color.Blue, null);
	presentation.Save("SomePresentation-out.pptx", SaveFormat.Pptx);
}

另请参见