跳到主要内容

SEARCH

返回从左到右读取时首次找到特定字符或文本字符串的字符位置(不区分大小写)。

语法

expression.SEARCH(arg1, arg2, arg3);

expression - 表示 ApiWorksheetFunction 类的变量。

参数

名称必需/可选数据类型默认值描述
arg1必需ApiRange | ApiName | string要查找的文本。可以使用 ? 和 * 通配符。使用 ~? 和 ~* 查找 ? 和 * 字符。
arg2必需ApiRange | ApiName | string要在其中搜索指定文本的文本。
arg3可选ApiRange | ApiName | number搜索文本中从左边开始计数的开始搜索的字符编号。如果省略,则使用 1。

返回值

number

示例

查找电子表格中文本字符串在单元格内出现的位置。

// How do I locate the position of text within a longer string in a spreadsheet?

// Search for a word and get its character position in a spreadsheet.

let worksheet = Api.GetActiveSheet();
let func = Api.WorksheetFunction;
worksheet.GetRange("A1").SetValue(func.SEARCH("line", "Online Office"));