Houdini 20.5 Nodes APEX nodes

string::Format

Creates a formatted string from input values.

On this page
Since 20.0

Outputs a string using a subset of the Python format syntax. Notably, only indexed arguments are supported, not named ones.

As with the printf() formatting, the format string contains replacement fields that are substituted by the textual representation of the inputs. The replacement fields for this formatter are surrounded by curly braces {}, rather than prefixed with a %.

Note that the string {{ or }} results in a single { or } being output.

Format Grammar

The grammar for the replacement field is as follows:

{[<index>][:<spec>]}

The <index> is an optional integer value that refers to the position of the argument after the format string. If the <index> is omitted for all replacement fields, they are automatically substituted with 0, 1, 2, .... It is not permitted to mix indexed and non-indexed replacement fields.

If a colon separator is found, the string after the colon is interpreted as a formatting specification. The grammar for the <spec> field is as follows:

[[<fill>]<align>][<sign>][#][,][0][<width>][.<precision>][<type>]

Field

Description

<fill>

The fill character to use when the width of the field is greater than the length of the argument value being printed.

<align>

A single character code that sets the alignment of the value within the field:

  • <: The field is left-aligned. This is the default for non-numeric values.

  • >: The field is right-aligned. This is the default for numeric values.

  • ^: The field is center-aligned.

  • =: The field is number aligned. This is the same as right-aligned, except the fill value is inserted between the sign indicator and the numeric value. This alignment is only available for numeric values.

<sign>

A single character that specifies how the sign is printed for numeric values:

  • +: Always print a sign, whether positive or negative.

  • -: Only print a sign when the number is negative.

  • <space>: Use a leading space on positive numbers, and a minus sign for negative numbers.

#

This option is only available for binary, octal or hexadecimal outputs. It indicates that they should be prefixed with '0b', '0' and '0x', respectively.

,

This option adds digit grouping to numerical outputs. For float numbers, this only applies to the integer portion of the float.

<width>

Specifies the minimum width of the field. Arguments wider than this value are still printed out in full. Preceding the width field with 0 automatically sets the alignment to number alignment, and the fill value to 0.

<precision>

Sets the precision for floating point numbers. For other types, it specifies the maximum width of the field.

<type>

A single character code that specifies how the type should be interpreted. If an argument type is not valid for the formatting type, the formatting type is ignored. The supported types are:

  • b: Output integers as binary numbers.

  • B: Output integers as binary numbers with an uppercase prefix (if using the # option).

  • c: Output integers interpreted as a Unicode code point.

  • d: Output integers as decimal numbers. This is the default for integers.

  • e: Use the exponent notation for floating point numbers.

  • E: Same as e, except the exponent separator is uppercase.

  • f: Use the fixed point notation for floating point numbers.

  • F: Same as f.

  • g: Format a floating point number as either fixed point or scientific, depending on its magnitude, which mostly results in the shortest form being used. This is the default for floats.

  • G: Same as g, except the exponent separator is uppercase.

  • o: Output integers as octals.

  • x: Output integers and floats as hexadecimal. For floats, this uses the special hexadecimal float output.

  • X: The same as x, except all alphabetic digits and prefixes are output in uppercase.

  • %: Takes a floating point number, multiplies it by 100, and outputs it with a percentage sign appended, using fixed point notation. The default precision in this mode is 2.

Inputs

formatstring: String

The formatted string where {} substrings are replaced with their corresponding input values.

args: VariadicArg<void>

Input values whose values are replaced in the formatstring.

Outputs

result: String

The formatstring replaced with the args input values.

APEX nodes