跳到主要内容

SearchAndReplace

查找并替换文本。

语法

expression.SearchAndReplace(oProperties);

expression - 表示 ApiDocument 类的变量。

参数

名称必需/可选数据类型默认值描述
oProperties必需Object查找和替换的属性。
oProperties.searchString必需string搜索字符串。
oProperties.replaceString必需string替换字符串。
oProperties.matchCase可选stringtrue是否区分大小写。

返回值

boolean

示例

此示例展示如何进行查找和替换。

// How to search for a specific word and replace it with another one.

// Search the first string and replace it with the second one.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
paragraph.AddText("This is the first sample text. The serial number of this sample text was replaced here.");
doc.SearchAndReplace({"searchString": "first", "replaceString": "second"});