This topic describes the syntax of conversion functions and provides parameter description and function examples.

Functions

Type Function Description
Basic type conversion ct_int Converts the value of a field or an expression to an integer.
ct_float Converts the value of a field or an expression to a floating-point number.
ct_str Converts the value of a field or an expression to a string.
ct_bool Converts the value of a field or an expression to a Boolean value.
Number conversion ct_chr Converts the ANSI or Unicode value of a field or an expression to a character.
ct_ord Converts the value of a field or an expression to an ANSI or a Unicode value.
ct_hex Converts the value of a field or an expression to a hexadecimal number.
ct_oct Converts the value of a field or an expression to an octal number.
ct_bin Converts the value of a field or an expression to a binary number.

ct_int

  • Syntax
    ct_int(value, base=10)
  • Parameters
    Parameter Type Required Description
    value Number or numeric string Yes The value to be converted.
    base Number No The base of the value to be converted. Default value: 10. If the value of base is 8, the function converts an octal value to a decimal value.
  • Response

    The converted integer.

  • Examples
    • Example 1: Convert a string to an integer.
      Raw log:
      number: 2
      Transformation rule:
      e_set("int_number", ct_int(v("number")))
      Transformation result:
      number: 2
      int_number:  2
    • Example 2: Convert a hexadecimal value to a decimal value.
      Raw log:
      number: AB
      Transformation rule:
      e_set("int_number", ct_int(v("number"),base=16))
      Transformation result:
      number: AB
      int_number:  171

ct_float

  • Syntax
    ct_float(value)
  • Parameters
    Parameter Type Required Description
    value Number or numeric string Yes The value to be converted.
  • Response

    The converted floating-point value.

  • Example: Convert an integer to a floating-point value.
    Raw log:
    price: 2
    Transformation rule:
    e_set("price_float", ct_float(v("price")))
    Transformation result:
    price: 2
    price_float:  2.0

ct_str

  • Syntax
    ct_str(value)
  • Parameters
    Parameter Type Required Description
    value Any type Yes The value to be converted.
  • Response

    The converted string.

  • Example: Convert an integer to a string.
    Transformation rule:
    e_set("ct_str", ct_str(b'test byte'))
    Transformation result:
    ct_str: test byte

ct_bool

  • Syntax
    ct_bool(value)
  • Parameters
    Parameter Type Required Description
    value Any type Yes The value to be converted.
  • Response

    The converted Boolean value.

  • Examples
    Raw log:
    num: 2
    Transformation rule:
    e_set("ct_bool", ct_bool(v("number")))
    Transformation result:
    num: 2
    ct_bool: true

ct_chr

  • Syntax
    ct_chr(value)
  • Parameters
    Parameter Type Required Description
    value Number or numeric string Yes The value to be converted.
  • Response

    The converted character.

  • Example: Convert a number to a character.
    Raw log:
    number: 78
    Transformation rule:
    e_set("ct_chr", ct_chr(v("number")))
    Transformation result:
    number: 78
    ct_chr: N

ct_ord

  • Syntax
    ct_ord(value)
  • Parameters
    Parameter Type Required Description
    value String Yes The value to be converted, whose length is 1.
  • Response

    The converted ANSI or Unicode value.

  • Example: Convert a string to an ANSI or a Unicode value.
    Raw log:
    world: a
    Transformation rule:
    e_set("ct_ord", ct_ord(v("world")))
    Transformation result:
    world: a
    ct_ord: 97

ct_hex

  • Syntax
    ct_hex(value)
  • Parameters
    Parameter Type Required Description
    value Number or numeric string Yes The value to be converted.
  • Response

    The converted hexadecimal number.

  • Example: Convert a number to a hexadecimal number.
    Raw log:
    number: 123
    Transformation rule:
    e_set("ct_hex", ct_hex(v("number")))
    Transformation result:
    number: 123
    ct_hex: 0x7b

ct_oct

  • Syntax
    ct_oct(value)
  • Parameters
    Parameter Type Required Description
    value Number or numeric string Yes The value to be converted.
  • Response

    The converted octal number.

  • Example: Convert a number to an octal number.
    Raw log:
    number: 123
    Transformation rule:
    e_set("ct_oct", ct_oct(v("number")))
    Transformation result:
    number: 123
    ct_oct: 0o173

ct_bin

  • Syntax
    ct_bin(value)
  • Parameters
    Parameter Type Required Description
    value Number or numeric string Yes The value to be converted.
  • Response

    The converted binary number.

  • Example: Convert a number to a binary number.
    Raw log:
    number: 123
    Transformation rule:
    e_set("ct_bin", ct_bin(v("number")))
    Transformation result:
    number: 123
    ct_bin: 0b1111011