Appearance
StringByte
返回字符串指定范围i-j
的ASCII 码
,i 的默认值为 1,即第一个字节,j 的默认值为 i 。
Lua字符串的字节下标是从 1 开始的
业务属性
属性 | 含义 | 说明 | 输入限定 | 示例值 |
---|---|---|---|---|
enable | 是否启用该控件,未启用时不编译 | 是否编译 | 选择值 | 启用 |
name | 控件返回值命名 | 控件输出值变量名 | 常量 | StringByte |
text | 与控件关联的文本 | 设计页控件显示 | 常量 | StringByte |
input | 输入参数 | 常量 /流程变量 | abc | |
startIndex | 起始索引 | 常量 /流程变量 | 1 | |
endIndex | 截止索引 | 常量 /流程变量 | 2 | |
output | 控件返回值变量命名 | 常量 | o1,o2 |
该控件具有若干个返回值,返回值的个数由输入参数的长度决定,所以需要定义若干个返回变量进行接收。
当参数长度
大于控件返回值定义个数
时,多余的返回值就被丢弃。例如参数为xyz
,此时参数长度为3
,若只定义一个返回值变量,将只返回字符x
的ASCII 码
。
当返回值定义个数
大于参数长度
时,多余的返回值变量将会为nil
。例如参数为xyz
,此时参数长度为3
,却定义了a,b,c,d,e,f
6个返回值变量,此时d,e,f
三个变量将为nil
。
起始索引及截止索引的默认值为1
,所以当这两个参数为nil
或者为1
时,控件将只有一个返回值。
使用示例
单个返回值
参数输入:abc
,起始索引及截止索引为空,此时将只有一个返回值既字符a
的ASCII 码
,所以只需定义一个返回值:output1

输出控件返回output1
,data属性为:
json
{
"output1": "#{output1}"
}
{
"output1": "#{output1}"
}

使用curl请求接口:
$ curl http://localhost:6636/api/stringByte
$ curl http://localhost:6636/api/stringByte
接口返回:
json
{
"output1": 97
}
{
"output1": 97
}
将起始索引修改为:3
,截止索引依旧为空,此时依旧只有一个返回值既字符c
的ASCII 码

使用curl请求接口:
$ curl http://localhost:6636/api/stringByte
$ curl http://localhost:6636/api/stringByte
接口返回:
json
{
"output1": 99
}
{
"output1": 99
}
多个返回值
参数输入:#{body.string}
,起始索引:#{body.start}
,截止索引:#{body.end}
,定义返回值变量:op1,op2,op3

多个变量之间使用英文
,
进行隔开
输出控件data属性:
json
{
"a": "#{op1}",
"b": "#{op2}",
"c": "#{op3}"
}
{
"a": "#{op1}",
"b": "#{op2}",
"c": "#{op3}"
}


使用curl请求接口:
$ curl http://localhost:6636/api/stringSub -d "{ \"string\": \"abc\", \"start\": 1, \"end\": 3 }"
$ curl http://localhost:6636/api/stringSub -d "{ \"string\": \"abc\", \"start\": 1, \"end\": 3 }"
接口返回:
json
{
"a": 97,
"b": 98,
"c": 99
}
{
"a": 97,
"b": 98,
"c": 99
}