跳到主要内容

MID

根据起始位置和长度,返回文本字符串中间的字符。

语法

expression.MID(arg1, arg2, arg3);

expression - 表示 ApiWorksheetFunction 类的变量。

参数

名称必需/可选数据类型默认值描述
arg1必需ApiRange | ApiName | string要从中提取字符的文本字符串。
arg2必需ApiRange | ApiName | number要提取的第一个字符的位置。第一个文本字符是 1。
arg3必需ApiRange | ApiName | number要提取的字符数。

返回值

string

示例

此示例演示如何根据起始位置和长度返回文本字符串中间的字符。

// How to get characters from the middle of the string indicating an index and length.

// Use a function to get an array of characters from the middle of a string.

let worksheet = Api.GetActiveSheet();
let func = Api.WorksheetFunction;
worksheet.GetRange("A1").SetValue(func.MID("Online Office", 3, 4));