Files
bugltd-ComfyLab-Pack/wiki/node reference/format.md
T
Bug, Ltd. cc6775802d prepare for publication (#3)
* create the files needed for publication on ComfyUI-Manager and Comfy Registry
* init the README
* small adjustments to the wiki
2025-01-21 19:27:31 +01:00

2.6 KiB

Node reference: Format (String / Multiline)

>> Link to the tutorials

Overview

The Format nodes are very simple yet powerful nodes, that are based on the standard Python string format() method.
They exist in 2 flavors: String or Multiline.

They are useful to create a string from a template, and any number of inputs.
Inputs can be of the following ComfyUI types: STRING, INT, FLOAT, BOOLEAN.

How to use

Here we will just cover the most basic usage, but please note that Python string format() allows to do very interesting things, beyond the standard string replacement: padding, truncating, ...

Simple usage

The node takes any number of inputs, that are automatically incremented: arg0, arg1, ...

Given the following template: first arg by name: {arg0}, second by index: {1}, and 2 input strings (tata and toto), we will get the resulting string: first arg by name: tata, second by index: toto.

Here we see that we can reference the inputs either by their name (argN), or by their index (starting at 0).
Straightforward, isn't it?

This way, it's very simple to concatenate 2 strings, append text to a string, ... many operations in one single node!

And last but not least: at stated above, it can take other types than strings: integer, float, boolean (and surely others).

Going further

For more details and advanced techniques, you can check:

Inputs / Widgets / Outputs

Inputs (unlimited)

input name type description comment
arg0 STRING, INT, FLOAT, BOOLEAN input value can also be referenced by index: 0
...
argN STRING, INT, FLOAT, BOOLEAN input value can also be referenced by index: N

Widgets

widget name type description comment
format STRING template string

Outputs

output name type description comment
formatted STRING result string after format