跳到主要内容

Search

在段落对象的范围内搜索。搜索结果是 ApiRange 对象的集合。

语法

expression.Search(sText, isMatchCase);

expression - 表示 ApiParagraph 类的变量。

参数

名称必需/可选数据类型默认值描述
sText必需string搜索字符串。
isMatchCase必需boolean是否区分大小写。

返回值

ApiRange[]

示例

在段落内搜索单词并在文档中将第一个匹配项设为粗体。

// How do I find a specific word within a paragraph in a document?

// Highlight a search result by applying bold formatting to the found text in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
paragraph.AddText("This is just a sample text. This text was added to the paragraph.");
let searchResults = paragraph.Search("text");
searchResults[0].SetBold(true);