ReplaceText

IPresentation.ReplaceText 方法

替换所有指定文本的出现次数为另一个指定文本。

public void ReplaceText(string oldText, string newText, ITextSearchOptions options, 
    IFindResultCallback callback)
参数类型描述
oldTextString需要被替换的字符串。
newTextString用于替换所有 oldText 出现的字符串。
optionsITextSearchOptions文本搜索选项 ITextSearchOptions
callbackIFindResultCallback接收搜索结果的回调对象 IFindResultCallback

示例

以下示例代码演示了如何用一个指定字符串替换另一个指定字符串。

[C#]
using (Presentation presentation = new Presentation("SomePresentation.pptx"))
{
    // 用 '***' 替换所有单独的 'the' 出现
    presentation.ReplaceText("the", "***", new TextSearchOptions() {WholeWordsOnly = true}, null);
    presentation.Save("SomePresentation-out2.pptx", SaveFormat.Pptx);
}

另请参阅