Nodes/ComfyUI-UsefulStuffNodes/String Match Switch
ComfyUI Node

String Match Switch

Route by exact text match, with a default that always saves you

By ArtemKo7v·Created 25 days ago·Updated a day ago· 0
String Match Switch
  • default
  • selected
match

Most switches in ComfyUI are wired to a seed or a boolean. String Match Switch is wired to a piece of text: give it a string to compare, a list of options each tagged with its own control string, and it hands back the option whose tag matches - or a fallback you provide if nothing does. It's a switch/case statement for your graph, and because the compared value can come from anywhere, it's how you steer a workflow with a filename, a mode tag, or a caption an LLM just wrote.

How it works

Two required inputs and a variable number of option rows. match is the string you're testing. Each row is a pair: a value_N socket that can be literally any type, and a control_N text box next to it holding the string that row answers to. On execution the node walks the rows in ascending index order and returns the first value_N whose control_N equals match exactly. If no row matches - or you haven't connected any rows - it returns the required default input.

The exactness is the whole personality of the node. No case folding, no trimming, no substring matching, no wildcards or regex. Sunset and sunset are different strings, and sunset with a trailing space is a third. That's a feature when you're routing on a fixed token you control, and a silent footgun when the string comes from something that adds whitespace or capitalizes for you.

The UI builds itself as you go: connect a value and the frontend adds the next row with a fresh control box, and a row only participates if its value socket is connected. The ceiling is 63 option rows, plus default, so 64 slots total - more than anyone needs, but it's there if you're building a menu-driven workflow. Note that rows start at value_2, not value_1; conceptually default is the first slot, which is a tidy way of thinking about it.

Inputs and outputs that matter

  • match (STRING) - the value being tested. Wire it or type it; it's a normal text field.
  • default (wildcard, required) - what comes out when nothing matches. Wire something genuinely useful here rather than a dummy: the fallback is what you'll silently get every time a comparison fails, so a sensible default hides and survives most mistakes.
  • value_2value_64 with their control_2control_64 text boxes - your case list. First match in index order wins, so put the specific ones low.
  • selected (wildcard output) - the winning value, or default. Because the node's input sockets are type-erased, the frontend labels them all with the type of whatever you wired into default - keep every option the same type as your default and the graph stays readable.

The classic use is a top-level "mode" string. Feed a text node, a filename, or the short output of a captioning model into match, tag three branches with portrait, landscape, square, and the workflow picks its own path. It's also a decent way to hang prompts off a single control string, which is the same idea people build by hand with number-to-string plumbing and a separate wildcard extension.

Installing it

Manager, search ComfyUI Useful Stuff Nodes, or:

cd ComfyUI/custom_nodes
git clone https://github.com/ArtemKo7v/ComfyUI-UsefulStuffNodes
# restart ComfyUI, then reload the browser page

The pack has no pip dependencies and ships no models - empty requirements.txt, standard library only, which is unusually clean for a node pack and worth knowing if you've ever had a dependency cascade take out your install. Nodes land in the ArtemKo7v category. The browser reload matters here too: the growing option rows are a frontend script (web/js/string_match_switch.js), so on a stale page you'll see a node that won't add rows.

One pleasant contrast with its siblings: this node has no always-rerun override, because its output is a pure function of its inputs. It caches like a normal node, so it won't quietly slow down everything behind it.

Common issues

Everything falls through to default. Nine times out of ten it's whitespace or capitalization - a caption node adding a trailing newline, or an LLM title-casing your token. Print the match value with a text preview node rather than guessing. Typed-in control strings are stored in the workflow, so compare against what's actually in the box, not what you think you typed.

You matched the empty row. Leave match empty and the control boxes empty and the node happily returns that empty-tagged row instead of your default. Fill the controls or disconnect the rows.

Nothing but default ever comes out. Check that the value sockets are actually connected - an unwired row doesn't participate no matter what its control box says. The falling-through is silent, so this looks like a matching bug when it's a wiring one.

The output won't link where you want it. The node is wildcard-typed, so the frontend guesses the output type from whatever you wired into default. If selected is refused downstream, the mismatch is between default and that input, not the option that matched.

CategoryArtemKo7v

Inputs (2)

NameTypeDefaultDescription
matchSTRING
default*

Outputs (1)

NameTypeDescription
selected*