Appearance
StringFormat
根据参数,按照格式化表达式的规则返回格式化后的字符串。
Lua字符串的字节下标是从 1 开始的
业务属性
属性 | 含义 | 说明 | 输入限定 | 示例值 |
---|---|---|---|---|
enable | 是否启用该控件,未启用时不编译 | 是否编译 | 选择值 | 启用 |
name | 控件返回值命名 | 控件输出值变量名 | 常量 | resultStr |
text | 与控件关联的文本 | 设计页控件显示 | 常量 | StringFormat |
expression | 字符串表达式 | 常量 /流程变量 | %s and %s | |
input | 指示参数 | 多个输入值时以, 分割 | 常量 /流程变量 | abc,#{formatStr} |
编写字符串表达式的规则与绝大部分语言相同:由字符串常量
和指示
组成,指示
控制了每个参数放在字符串的什么位置,及如何放入它们。
常见的指示有:
- %d:用于十进制数
- %x:用于十六进制数
- %o:用于八进制数
- %f:用于浮点数
- %s:用于字符串
使用示例
保留小数
表达式输入:%.4f
(保留4位小数),参数输入:3.1415926

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

使用curl请求接口:
$ curl http://localhost:6636/api/stringFormat
$ curl http://localhost:6636/api/stringFormat
接口返回:
json
{
"data": "3.1416"
}
{
"data": "3.1416"
}
进制转换
表达式输入:%d %x %o
(十进制数31转换成其他进制),参数输入:31,31,31

多个输入参数之间使用英文
,
进行隔开
使用curl请求接口:
$ curl http://localhost:6636/api/stringFormat
$ curl http://localhost:6636/api/stringFormat
接口返回:
json
{
"data": "31 1f 37"
}
{
"data": "31 1f 37"
}
格式化字符串
表达式输入:#{body.pattern}
,参数输入:#{body.day}

使用curl请求接口:
$ curl http://localhost:6636/api/stringFormat -d "{ \"pattern\": \"today is %s\", \"day\": \"Friday\" }"
$ curl http://localhost:6636/api/stringFormat -d "{ \"pattern\": \"today is %s\", \"day\": \"Friday\" }"
接口返回:
json
{
"data": "today is Friday"
}
{
"data": "today is Friday"
}