Simple Expression Strings
Assemble text with a formula — the string builder nobody sells you
- STRING
ComfyUI's text nodes are great at one thing: merging a handful of inputs in order. The moment you want anything conditional - "if this is set, add that word", "repeat this character N times", "join these with a separator" - you're either juggling conditional nodes or giving up. Simple Eval Strings lets you write a small expression over three string inputs (a, b, c) and get a composed string back.
The default says it all: a + ' ' + b + c turns "Hello", "World", "!" into "Hello World!". That's the boring case. The useful ones are a.replace("bad", "good"), (b + ", " + c).upper(), or a * 3 when you need a repeated fragment. It's the smallest node in the pack and, for prompt builders, quietly one of the most convenient.
How it works
Same simpleeval engine as the numeric evaluators: a restricted Python expression evaluator, so you get string methods - +, * (repeat), .upper(), .lower(), .replace(), .join(), .strip(), indexing like b[0] - without arbitrary code execution. It's safe to run on workflow-controlled text, which is worth saying out loud given how many custom nodes won't guarantee that.
python_expression is where you type the formula, print_to_console echoes to the terminal for debugging, and the three inputs a/b/c are strings. Everything the expression touches is a string, so no type surprises.
One output: STRING, the evaluation result. That's it - no INT/FLOAT/STRING triple here, because there's only one type in the room.
Install
Ships inside ComfyUI Text Processor:
cd ComfyUI/custom_nodes
git clone https://github.com/rookiestar28/ComfyUI_Text_Processor.git
pip install -r requirements.txt
Restart after. Manager users: "ComfyUI Text Processor".
Gotchas
The inputs are strings even when you type numbers, so a * 2 repeats the text, it doesn't multiply a number - a * 2 with a="3" gives "33". If you need numeric behavior, that's the float/int evaluators' job. And since the expression is a Python subset, quoting matters: use single quotes inside the expression (a + ' ' + b) because the widget itself is one big string. Minor, but it's the classic first-run stumble. For building structured prompts from components - especially with .replace() cleaning up a wildcard or LLM output - this is the node that replaces three others.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| python_expression | STRING | a + ' ' + b + c | String expression evaluated with text variables a, b, and c. |
| print_to_console | COMBO | Print variables, expression, and result to the server console. | |
| aopt | STRING | Hello | Text value bound to variable a. |
| bopt | STRING | World | Text value bound to variable b. |
| copt | STRING | ! | Text value bound to variable c. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | String evaluation result. |