要在动态变量中使用的其他函数

在高级操作中,除了基于 MathJS 的函数之外,您还可以使用自定义函数:

字符串函数

indexOf(大海捞针、针)

如果在 “haystack” 字符串或列表中找到 “needle” 字符串,则该函数将返回其(从零开始)的位置,否则计算结果为-1。

示例
 indexOf("ABCD", "A") //returns 0
 indexOf("ABCD", "CD") //returns 2
 indexOf("ABCD", "E") //returns -1
 indexOf(["a","b","c"], "a") //returns 0
 indexOf(["a","b","c"], "bc") //returns -1

getIndexValue(大海捞针、索引)

如果 “index” 数字小于 “haystack” 列表,则该函数返回位于 “index” 位置的值,否则会出错。

示例
 getIndexValue(["a","b","c"], 0) //returns a
 getIndexValue(["a","b","c"], 1) //returns b

substr(字符串,开始 [,长度])

此函数返回原始字符串的子字符串,从从零开始的起始位置开始。 如果指定了 length,它将返回那么多个字符,否则返回字符串的其余部分。

示例
 substr("ABCD", 1) //returns "BCD"
 substr("ABCD", 2, 1) //returns "C"
 substr("ABCD", 5) //returns ""

slice(字符串,start [,end])

此函数返回原始字符串的子字符串,从从零开始的起始位置开始。 如果提供了结束位置,它将返回直到该位置的所有字符,但不包括该位置的字符。 否则,它将返回字符串的其余部分。

开始或结束的负位置从字符串的右侧开始计算。

示例
 slice("ABCD", 1) //returns "BCD"
 slice("ABCD", 0, 2) //returns "AB"
 slice("ABCD", 1, -1) //returns "BC"
 slice("ABCD", 2, 1) //returns ""

upper (字符串)

此函数返回提供的字符串,并将其转换为大写。

示例
upper("aBcD") //returns "ABCD"

更低(字符串)

此函数返回提供的字符串,转换为小写形式。

示例
lower("aBcD") //returns "abcd"

长度 (字符串)

此函数返回字符串的长度。

示例
 length("") //returns 0
 length("ABCD") //returns 4

逻辑函数

等于(值 1,值 2)

如果 value1 和 value2 的值和类型相同,则此函数返回 true,否则返回 false。 `value1 === value2` 的替代语法。(`value1 == value2` 是一个较弱的比较)

示例
 equal(2, 1) //returns false
 equal(1, 1) //returns true
 equal(1, "1") //returns false (different types)

iFelse(条件、值 Iif True、ValueIFalse)

此函数检查提供的条件。 如果条件为真(或 真值),则返回 valueIFTrue,否则返回 valueIFFalse。

示例
 ifElse(equal(1, 5), "equal", "not equal") //returns "not equal"
 ifElse(equal(2, 2), "equal", "not equal") //returns "equal"

正则表达式函数

匹配(值、模式 [、标志、groupIndex])

matchAll(值、模式、matchIndex [、标志])

这些函数执行正则表达式匹配并测试所提供的 “值” 是否与提供的正则表达式 “模式” 相匹配。 

可选的 flags 参数是一串单字母正则表达式标志,可启用高级行为( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#advanced_searching_with_flags )。 标志参数最常见的用法是传递“i”以进行不区分大小写的匹配。

这里有两个相关的函数:

  • 时间匹配函数查找单个匹配项并支持数字捕获组的高级用法,使用最后一个参数选择所需的捕获组(0 是整个匹配项,1 是第一个捕获组,依此类推)。
  • 全部匹配版本支持多个匹配,使用匹配索引参数来选择所需的匹配。 (0 是第一个匹配项,1 是第二个匹配项,依此类推。)

在这两种情况下,如果存在匹配项,则结果将是字符串内容,或者当用作动态布尔变量的正文时,如果存在匹配则为 true,如果没有匹配则为 false。

示例
// Basic usage
match("abc", "b.") // returns "bc" (or true as a Dynamic Boolean Variable)
match("abc", "c.") // returns no match (or false as a Dynamic Boolean Variable)

// Advanced usage

// Case-insensitive
match("aBc", "b.", "i") // returns "Bc", since casing was ignored with the "i" flag

// Capture Groups
match("acd bce", "b(c.)", "", 1); // returns "ce" - the whole match was "bce", but the first capture group is (c.)

// Multiple matches
matchAll("acd bce", "c.", 1); // returns "ce" - "c." matches both "cd" and "ce", the last argument (and usage of matchAll) selected the second one.

日期函数

格式化日期(日期 [,格式字符串])

取一个数字日期,并将其转换为人类可读的格式。  这对于在对代理进行一些数字操作后向其显示日期很有用。

自 1970 年 1 月 1 日以来的日期  值以毫秒为单位。

格式化字符串  接受Unicode 标准替代品。

注意: 生成的字符串将位于代理的时区中,因此在格式字符串中包含时区可能会有所帮助。
示例
// Default formatting
formatDate(946684800000)                                      // 01/01/2000 12:00:00 am (+00:00)
 
// Custom formatting
formatDate(946684800000, "eeee, MMMM do yyyy, h:mm:ss a (z)")     // Saturday, January 1st 2000, 12:00:00 am (GMT)
formatDate(946684800000, "eeee, MMMM do yyyy, h:mm:ss a (xxxxx)") // Saturday, January 1st 2000, 12:00:00 am (+00:00)

格式化日期 ISO(日期)

采用数字日期并将其转换为 ISO 8601 格式的格式化日期字符串。 这在您使用日期组件或将日期发送到 API 调用时很有用。 

自 1970 年 1 月 1 日以来的日期值以毫秒为单位。

注意: 生成的字符串将位于代理的时区中。

示例 
formatDateISO(946684800000)                    // 1999-12-31T19:00:00-05:00

日期到毫秒(日期)

获取字符串日期,并将其转换为毫秒数自 1970 年 1 月 1 日起,用于数字操作。

提供的日期应采用脚本变量使用的默认格式。

示例
dateToMilliseconds("01/01/2000 12:00:00 am (+00:00)"); // 946684800000

formatDate(dateToMilliseconds({{Scripter.Customer Call Start Time}}) + 5 * 60 * 1000) // Five minutes (multiplied by 60 sec/minute and 1000 ms/sec to convert to ms) after the customer was connected

格式持续时间(持续时间)

将以毫秒为单位的数字持续时间转换为人类可读的格式。  

示例
formatDuration(5 * 1000 * 60 + 55); // "00:05:55"

持续时间到毫秒(持续时间字符串)

将字符串持续时间转换为数值。

示例
durationToMilliseconds({{Scripter.Customer Call Duration}}) // How long has the customer been connected

formatDuration(5 * 1000 * 60 - durationToMilliseconds({{Scripter.Customer Call Duration}})) // Countdown until the customer has been on the line for five minutes