内置函数

内置函数

函数是一组代码,它接受有限数量的输入并可选择返回一个值。

 字符串函数

作用于字符串表达式的函数被归类为字符串函数,它们包括用于查找给定文本的长度、从文本中删除某些单词等等的函数。

在所有给定函数中,原始字符串不会被函数更改,只有返回值受这些函数的影响。

运算符格式**描述
+<string1> + <string2>并置两个字符串
contains(<string>)<string1>.contains(<string2>)返回:布尔值
如果 string2 是 string1 的子串,那么返回 true
endsWith(<string>)<string1>.endsWith(<string2>)返回:布尔值
如果 string1 以 string2 结尾,那么返回 true
startsWith(<string>)<string1>.startsWith(<string2>)返回:布尔值
如果 string1 以 string2 开头,那么返回 true
remove(<string>)<string>.remove(<substring>)从给定字符串中移除子串。
removeFirstOccurence()<string>.removeFirst
Occurence(<substring>)
从给定字符串中移除子串的第一个实例。
removeLastOccurence()<string>.removeLast
Occurence(<substring>)
从给定字符串中移除子串的最后一个实例。
getSuffix()<string>.getSuffix(<substring>)获取指定子串之后的字符串。
getPrefix()<string>.getPrefix(<substring>)获取指定子串之前的字符串。
toUpperCase()<string>.toUpperCase()将字符串转换为大写。
toLowerCase()<string>.toLowerCase()将字符串转换为小写。
getAlphaNumeric()<string>.getAlphaNumeric()仅保留指定字符串中出现的字母数字。
getAlpha()<string>.getAlpha()仅保留指定字符串中出现的字母。
removeAllAlphaNumeric()<string>.removeAll
AlphaNumeric()
移除指定字符串中出现的所有字母数字。
removeAllAlpha()<string>.removeAllAlpha()移除指定字符串中出现的所有字母。
length()<string>.length()获取给定字符串的长度。
getOccurenceCount()<string>.getOccurence
Count(<substring>)
获取某个子串在给定字符串中的出现次数。
indexOf()<string>.indexOf(<substring>)获取该子串在给定字符串中的第一个实例的序号。
lastIndexOf()<string>.lastIndexOf(<substring>)获取该子串在给定字符串中的最后一个实例的序号。
substring(<s.index>, <e.index>)<string1>.substring(<
s.index>, <e.index>)
返回从指定起始序号到结束序号的子串。
起始序号
和结束序号值是从 0 开始指定的数字,
(即)您在主字符串中引用位置时从 0 开始编号,
字符串中的第二个位置为为 1,第三个位置为 2,以此类推...


- 起始序号值是主字符串中要提取至子串的第一个字符的位置。



- 结束序号值是主字符串中要停止提取至子串的字符的位置,
而不是主字符串中要提取至子串的最后一个位置的位置。

trim()<string>.trim()从字符串中移除所有前导空格和结尾空格
equalsIgnoreCase
(<string>)
<string1>.equalsIgnoreCase
<string2>
如果 <string1> 等于 <string2>,那么返回 true
toString()<expression>.toString将任意类型的表达式转换为字符串。
应用至日期/时间值时,请参阅 toString() 的行为。
matches()<string expression>.matches
(<regular expression>)
如果给定字符串与给定为自变量的正则表达式匹配,那么返回 true。

例如:
  1. phone = "(123) 456 7890";
  2. if(phone.matches("^\(?([0-9]{3})\)?[-.]?([0-9]{3})[-.]?([0-9]{4})$") == false)
  3. {
  4. Info "Please enter a valid Phone format";
  5. }
 replaceAll(searchString,
replacementString, [escapeRegEx])
<String>.replaceAll
(<searchString>,
<replacementString>
,false)
将与给定 <searchString> 表达式匹配的字符串的所有实例替换为给定 <replacementString>

例如:


searchVariable="Jack and Jill went up the hill to fetch
a pail of water";
searchString="Jack";
replacementString="Bill";
resultVariable = sourceVariable.
ReplaceAll(searchString,replacementString);
//returns "Bill and Jill went up the hill
to fetch a pail of water"


input.Address = "Suite 123, 4523 Yonge
Street, Toronto";
input.Address = input.Address.replaceAll("23","9945");
//returns "Suite 19945, 459945 Yonge Street, Toronto"

默认情况下,replaceAll() 函数支持正则表达式,
(即)它不会
在源字符串中查找并替换 $、* 等等的特殊字符。


参数 [escapeRegEx] 是一个可选
布尔值参数,此参数用于指定在执行 replaceAll() 函数时 Zoho Creator 是否支持正则表达式。


  • true 指示不支持对 replace 函数使用正则表达式。
  • false 指示支持对 replace 函数使用正则表达式。
    默认情况下,此值被视为“false”。

注:如果未指定 escapeRegEx 参数的值,那么我们会将值视为“false”。

即,默认情况下,正规表达式在 replace 函数上受支持。
例如,以下两个函数将执行同一操作:


replaceAll("OnlineLine DB","Creator",false)
replaceAll("OnlineLine DB","Creator")

replaceFirst(searchString,
replacementString,[escapeRegEx])
<String>.replaceFirst
(<searchString>,
<replacementString>,
false)
将与给定
<searchString>
表达式匹配的字符串的第一个实例替换为给定 <replacementString>。

默认情况下,replaceFirst 函数支持正则表达式,
(即)它不会
在源字符串中查找并替换 $、* 等等的特殊字符。


参数 [escapeRegEx] 是一个可选布尔值参数,此参数用于指定在执行 replaceFirst() 函数时 Zoho Creator 是否支持正则表达式。


  • true 指示不支持对 replace 函数使用正则表达式。
  • false 指示支持对 replace 函数使用正则表达式。
    默认情况下,此值被视为“false”。

注:如果未指定 escapeRegEx 参数的值,那么此值被视为“false”。

注:

  • 在上表中,<string>,<string1>,<string2>, <substring> 全部为 <string expression>
  •  应用于 datetime 值时 toString() 的行为:
    • 作用于 date/datetime 的 <date/datetime>.toString() 函数将按应用程序设置中指定的格式输出日期字符串。
    • 如果要覆盖它,那么可使用 <date/datetime>.toString("date format as string")。例如,toString("dd-MM-yyyy")
    • 如果要转换为不同时区的字符串,那么可使用 <date/datetime>.toString("date format as string","<Time Zoho>")。例如,toString("dd-MM-yyyy","Asia/Calcutta")
  • 下面讨论日期和时间模式字符串:
    • 日期 - dd
    • 月份 - MM(或)MMM(或)MMMM
    • 年份 - yy(或)yyyy
    • 12 小时格式 - hh
    • 24 小时格式 - HH
    • 分钟 - mm
    • 秒 - ss
    • AM/PM 标记 - a

 数值函数

作用于数值的函数被归类为数值函数:

在所有给定函数中,原始数字不会被函数更改,只有返回值受这些函数影响。

运算符格式描述
sin()格式:<numeric>.sin()
返回:数字
返回给定角度的三角正弦
sqrt()格式:<numeric>.sqrt()
返回:数字
返回给定值的正确舍入的正平方根
tan()格式:<numeric>.tan()
返回:数字
返回角度的三角正切。
toDecimal()格式:<expression>.toDecimal()
返回:小数
返回给定表达式生成的小数值。
toLong()格式:<expression>.toLong()
返回:数字
返回给定表达式生成的长整数值。十六进制字符串之前应加上“0x”。例如,“0x1F”。toLong() 返回“1F”的十六进制值。
round()格式:<numeric>.round(<precision-numeric>)返回舍入至指定位数的数字后的数字。
log()格式:<numeric>.log()返回指定数字的对数值 (LogeN)。

 布尔字符串函数

这些函数作用于两个字符串表达式并返回一个布尔值表达式。

运算符用法发生以下情况时返回 true
==<string1> == <string2>两个字符串表达式相等
contains()<string1>.contains(<string2>)string2 为 string1 的子串
startsWith()<string1>.startsWith(<string2>)string1 以 string2 开头
endsWith()<string1>.endsWith(<string2>)string1 以 string2 结尾

 日期函数

运算符格式返回
getDay()<date>.getDay()
,其中 <date> 是类型为“date”的表单字段。
返回 1 到 31 之间的数字,表示该日期所在月份的日子。
getMonth()<date>.getMonth()
,其中 <date> 是类型为“date”的表单字段
返回 1 到 12 之间的数字,表示该日期所在年份的月份。
getYear()<date>.getYear()
,其中 <date> 是类型为“date”的表单字段
返回该日期的年份。
getWeekOfYear()<date>.getWeekOfYear()
,其中 <date> 是类型为“date”的表单字段
返回 1 到 52 之间的数字,表示该周在当年的编号。例如,“16/1/2007”返回 3。
getDayOfWeek()<date>.getDayOfWeek()
,其中 <date> 是类型为“date”的表单字段
返回 1 到 7 之间的数字,表示该日期所在周的日子的编号。数字“1”表示周日,“2”表示周一,以此类推。
getDayOfYear()<date>.getDayOfYear()
,其中 <date> 是类型为“date”的表单字段
返回 1 到 365 之间的数字,表示该日期所在年份的日子的编号。
addDay()<date/time>.addDay(<numeric>)返回加上指定天数之后的日期。
addMonth()<date/time>.addMonth(<numeric>)返回加上指定数目的月之后的日期。
addWeek()<date/time>.addWeek (<numeric>)返回加上指定数目的周之后的日期。
addYear()<date/time>.addYear(<numeric>)返回加上指定数目的年之后的日期。
subDay()<date/time>.subDay(<numeric>)返回减去指定天数之后的日期。
subMonth()<date/time>.subMonth(<numeric>)返回减去指定数目的月之后的日期。
subWeek()<date/time>.subWeek(<numeric>)返回减去指定数目的周之后的日期。
subYear()<date/time>.subYear(<numeric>)返回减去指定数目的年之后的日期。
toDate()<string>.toDate()<string>.toDate() 函数始终使用应用程序设置中指定的格式解析输入字符串,如果它无法将该字符串转换为日期,那么将抛出错误。如果要覆盖它,那么可使用 <string>.toDate("date format as string")
例如:toDate("dd-MM-yyyy")
toTime()<string>.toTime() <string>.toTime() 函数始终使用应用程序设置中指定的格式解析输入字符串,如果它无法将该字符串转换为日期时间,那么将抛出错误。
如果要覆盖它,那么可使用 <string>.toTime("date format as string")。例如:toTime("dd-MM-yyyy")

 时间函数

运算符格式返回
addHour()<date-time>.addHour(<numeric>)返回加上指定数目的小时之后的日期。
addMinutes()<date-time>.addMinutes(<numeric>)返回加上指定数目的分钟之后的日期。
addSeconds()<date-time>.addSeconds(<numeric>)返回加上指定数目的秒之后的日期。
getHour()<date-time>.getHour()返回当天对应的小时
getMinutes()<date-time>.getMinutes()返回对应小时内的分钟数
getSeconds()<date-time>.getSeconds()返回对应分钟内的秒数
subHour()<date-time>.subHour(<numeric>)返回减去指定数目的小时之后的日期。
subMinutes()<date-time>.subMinutes(<numeric>)返回减去指定数目的分钟之后的日期。
subSeconds()<date-time>.subSeconds(<numeric>)返回减去指定数目的秒之后的日期。

 列表函数

运算符格式返回
contains()<list>.contains(<element>)返回:布尔值
如果该元素存在于列表中,那么返回“true”
get()<list>.get(<index>)返回:元素
返回指定位置的元素(第一个元素的序号为“0”)
indexOf()<list>.indexOf(<element>)返回:数字
返回列表中给定元素的位置(第一个元素的位置为“0”)
lastIndexOf()<list>.lastIndexOf(<element>)返回列表中该元素的最后一个实例的位置。
remove()<list>.remove(<index>)移除并返回具有指定序号的元素(第一个元素的编号为“0”)
sort()<list>.sort(<optional boolean>)返回:列表
返回使用所排序顺序的列表。可选布尔值指定升序 (true)/降序 (false)
size()<list>.size()返回列表中的元素数目。
isempty()<list>.isempty()返回:布尔值
列表为空时返回“true”,否则返回“false”
sublist()<list>.sublist(<start index>,<optional endIndex>)返回:列表
从给定起始序号到指定结束序号的子列表(如果未给定 endIndex,那么返回从给定起始序号到列表结束的子列表)
toList()<string>.toList(<optional separator>)返回:列表
将字符串转换为使用给定分隔符的列表(默认分隔符为“,”,即逗号)
{}{<optional comma separated elements>}返回:列表
创建具有给定元素的列表。如果未给定元素,那么返回空列表。
List()List()返回:列表
创建空列表。
List:String()List:String()返回:列表
创建空字符串列表。此列表只能包含字符串元素
List:Int()List:Int()返回:列表
创建空整数列表。此列表只能包含整数元素。
List:Date()List:Date()返回:列表
创建空日期列表。此列表只能包含日期/日期时间元素。
List:Bool()List:Bool()返回:列表
创建空布尔值列表。此列表只能包含布尔值。
List:Float()List:Float()返回:列表
创建空小数列表。此列表只能包含小数值。

 映射函数

运算符格式返回
get(<string>)<map>.get(<string>)返回所指定键在此身份散列映射中映射至的字符串值。如果映射未包含对应此键的映射,那么将返回空值。
size()<map>.size()返回表示给定映射的大小的数字。
isEmpty()<map>.isEmpty()返回布尔值:如果此映射未包含键/值映射,那么返回 True;
如果此映射包含键/值映射,那么返回 False。
containKey(<string>)<map>.containKey(<string>)返回布尔值:如果此映射包含对应所指定键的映射,那么返回 True;
如果此映射未包含对应所指定键的映射,那么返回 False。
containValue(<value>)<map>.containValue(<value>)返回布尔值:如果此映射将一个或多个键映射至所指定值,那么返回 True;否则返回 False
keys()<map>.keys()返回此映射中包含的键的列表。
toMap()<string>.toMap()返回来自给定 JSON 格式的字符串的映射
Map()Map()返回空映射

 XML 函数

运算符格式返回
execute(<string>)<xml>.execute(<string>)返回来自给定 xpath 和 xml 的带格式字符串
toXML()<string>.toXml()返回来自给定字符串的 Xml

 URL 函数

运算符格式返回
getUrl(<string>)getUrl(<url-string>)返回包含响应信息的映射
postUrl(<string>,<map>)postUrl(<url-string>,<data-map>)返回包含响应信息的映射
encodeUrl(<string>)encodeUrl(<url-string>)对“所有空格字符”和“URL 字符串中不允许的其他字符”进行编码,然后返回编码字符串。例如,
myURL = "http://www.test/zohotest?name=John Doe&country=New Zealand&age=101";
myEncodedURL = encodeUrl(myURL);
可在 getURL()、postURL() 和 openURL() Deluge 任务中使用此函数对所需 URL 进行编码,然后传递所编码 URL 字符串。例如,
userName=encodeUrl(input.Name);
openUrl("#View:SampleHTML?userName="+userName, "new window");

 表单数据函数

运算符格式返回
getFieldNames()getFieldNames()返回包含表单中的所有字段的列表字符串。
getFieldNames 仅在 onSuccess 操作中受支持
getFieldValue()getFieldValue(<field-name>)返回给定字段的值。

样本应用程序 GetFieldNames表单 A -> 添加时 -> 成功时功能块中使用 getFieldNames()getFieldValue() 函数。此脚本迭代每个列表值(字段名称)并获取此字段的值。字段名称和值将在用户变量“fieldNameVsVal”中更新,并用于 sendmail() 任务的消息块。

还没有找到您需要的内容?

请发送邮件给我们:support@zohocorp.com.cn