Nodes/More Math/String math
ComfyUI Node

String math

String manipulation with a real function library, not six nodes

By mcDandy·Created about a year ago·Updated 3 days ago· 5
String math
  • V
  • F
  • Expression
  • stack
  • STRING
  • STACK
batching0
remember_stackfalse

ComfyUI's string handling is famously thin. Want to uppercase a tag, split a comma list, or swap a word in a filename? You're chaining "String" nodes that each do exactly one thing. String math from More Math gives the same expression engine it gives every other type, pointed at text: upper(str), lower(str), trim(str), split(str, delimiter), join(list, sep), substring(str, start, length), find, replace - all callable in one expression, with if/else when you need branching.

What it's for

The genuinely useful pattern is batch string work. The node takes autogrow string inputs (V0, V1, ...), and the STRING output is a list, so you can feed it a batch of filenames or tags and get a transformed batch out the other side - perfect for filename generation, folder-structured saves, or building prompt lists programmatically. V in an expression is the list of all string inputs, and you can iterate it with the for (variable in expression) construct the language supports.

A concrete example: you've got a batch of LoRA names and want the display version. replace(trim(V0), "_", " ") per element, or loop over V and join with commas. The batching integer controls how many strings evaluate per pass.

Inputs and outputs

V is the autogrow string list, F the autogrow floats (handy for building strings with numbers - though you may need int()/float() conversions from the function library), and Expression is the formula. remember_stack and the optional stack input are the pack's state mechanism, only needed if you're threading values between nodes.

Outputs are STRING (a list) and STACK.

Installing it

Same as every node in this pack:

cd ComfyUI/custom_nodes
git clone https://github.com/mcDandy/more_math
cd more_math
pip install -r requirements.txt

Restart ComfyUI, or install "More math" from ComfyUI Manager. One dependency beyond torch: antlr4-python3-runtime. No models to download.

Gotchas

The expression language treats strings as strings - there's no implicit "string plus number" coercion, so concatenation is join or building lists and joining them, not +. Get the quoting right and it all works; get it wrong and you get a parse error with no graceful hint. Also note the output is a list even when you feed one string in, so if a downstream node wants a single string, grab index 0. And one real-world trap: substring is start-and-length, not start-and-end, so off-by-ones are your problem, not the node's. The pack is new and solo-maintained, so expect rough edges, but for anyone doing batch file workflows this is the string node you'll actually use.

CategoryMore math

Inputs (6)

NameTypeDefaultDescription
VCOMFY_AUTOGROW_V3
FCOMFY_AUTOGROW_V3
ExpressionSTRING,SYNTAX_TREEV0Expression to apply on weights
batchingINT0
remember_stackBOOLEANfalseIf enabled, stack is copied at output leading to changes being remembered during batch operations (node runs multiple times in sucession). If disabled each batch gets it's own copy of the stack.
stackoptSTACKAccess stack between nodes

Outputs (2)

NameTypeDescription
STRINGSTRING
STACKSTACK