跳转至

Format string(格式化字符串(Format string))

Supported in: Batch, Streaming

Formats string printf style.

Expression categories: String

Declared arguments

  • Format arguments: List of args to insert into format string.
    List\>
  • Format string: String to be formatted.
    Literal\

Output type: String

Examples

Example 1: Base case

Argument values:

  • Format arguments: [argument1, argument2]
  • Format string: Hello %s, my name is %s
argument1 argument2 Output
Alice Bob Hello Alice, my name is Bob
Jane John Hello Jane, my name is John

Example 2: Base case

Description: Formats an integer.

Argument values:

  • Format arguments: [4]
  • Format string: number = %d

Output: number = 4


Example 3: Base case

Description: Formats a double with a sign and 4 decimal places.

Argument values:

  • Format arguments: [2.718281828459045]
  • Format string: e = %+.4f

Output: e = +2.7183


Example 4: Null case

Argument values:

  • Format arguments: [argument1, argument2]
  • Format string: Hello %s, my name is %s
argument1 argument2 Output
null Bob Hello null, my name is Bob
Alice null Hello Alice, my name is null
null null Hello null, my name is null


中文翻译

格式化字符串(Format string)

支持:批处理(Batch)、流处理(Streaming)

按printf风格格式化字符串。

表达式类别: 字符串(String)

声明参数

  • 格式化参数(Format arguments): 待插入格式化字符串的参数列表。
    列表\<表达式\<布尔型(Boolean) | 字节型(Byte) | 日期型(Date) | 十进制数(Decimal) | 双精度浮点型(Double) | 单精度浮点型(Float) | 整型(Integer) | 长整型(Long) | 短整型(Short) | 字符串(String) | 时间戳(Timestamp)>>
  • 格式化字符串(Format string): 待格式化的字符串。
    字面量\<字符串(String)>

输出类型: 字符串(String)

示例

示例1:基础案例

参数值:

  • 格式化参数: [argument1, argument2]
  • 格式化字符串: Hello %s, my name is %s
argument1 argument2 输出(Output)
Alice Bob Hello Alice, my name is Bob
Jane John Hello Jane, my name is John

示例2:基础案例

描述: 格式化一个整型(Integer)。

参数值:

  • 格式化参数: [4]
  • 格式化字符串: number = %d

输出: number = 4


示例3:基础案例

描述: 格式化一个带符号且保留4位小数的双精度浮点型(Double)。

参数值:

  • 格式化参数: [2.718281828459045]
  • 格式化字符串: e = %+.4f

输出: e = +2.7183


示例4:空值案例

参数值:

  • 格式化参数: [argument1, argument2]
  • 格式化字符串: Hello %s, my name is %s
argument1 argument2 输出(Output)
null Bob Hello null, my name is Bob
Alice null Hello Alice, my name is null
null null Hello null, my name is null