In ComfyUI, “string function” refers to the built-in nodes that let you manipulate text values within your workflow—such as concatenating, formatting, searching, or splitting strings. The most common ones are the String Function node (found under utils) and the Text Multiline node, but you can also use Python-like operations via custom nodes. This article explains what these nodes do, how to use them, and how they fit into a broader ComfyUI workflow.
What Is ComfyUI and Why Strings Matter
ComfyUI is a node-based interface for Stable Diffusion image generation. You build workflows by connecting nodes that process inputs and outputs—models, prompts, images, and also text. Strings (text values) appear everywhere: positive and negative prompts, file names, seed values, and metadata. Without string functions, you would have to manually edit text in each node. With them, you can automate prompt variations, build dynamic file names, or pass text between different parts of your workflow.
The Core String Function Node
ComfyUI includes a node simply called String Function (in the utils category). It takes two string inputs, string_a and string_b, and applies a chosen operation. The available operations are:
concat– joinsstring_aandstring_btogether (e.g., “hello” + “world” = “helloworld”).add– same as concat (alias).length– returns the number of characters instring_a(ignoresstring_b).equal– returnstrueif both strings are exactly the same, otherwisefalse.contains– returnstrueifstring_acontainsstring_bas a substring.replace– replaces all occurrences ofstring_binstring_awith a third string (the node actually has a third input for the replacement, but the UI shows only two; you may need to add a third input via the node’s settings).split– splitsstring_aby the delimiterstring_band returns the first part (or a list, depending on version).
To use it, add the node via right-click > Add Node > utils > String Function. Connect a text input (like a prompt) to string_a, and another value to string_b. The output is a string (or boolean for equal and contains). This node is simple but limited—for more complex operations, you’ll need custom nodes or a Python script node.
How to Use String Functions in a Workflow
Here’s a typical example: you want to generate multiple images with different prompts by combining a base prompt with a style suffix. You could create a Text Multiline node with your base prompt (e.g., “a portrait of a cat”), and another Text node with a style (e.g., “in the style of Van Gogh”). Connect both to a String Function node set to concat, then connect the output to the positive_prompt input of a CLIP Text Encode node. Now, changing the style node automatically updates the prompt without editing the base text.
Another common use: generating dynamic file names for saving images. Use a String Function to combine a base name (like “portrait”) with the current seed value (converted to string) and an extension. This helps you organize outputs.
Choosing the Right String Node
ComfyUI’s default node set is minimal. For most users, the String Function node is enough for concatenation and simple checks. However, if you need more advanced operations—like regex, multi-part splits, or formatting with placeholders—you should install custom nodes. Popular packs include ComfyUI-Custom-Scripts (by pythongosssss) which adds a Show Text node and a Text node with multiple inputs, and ComfyUI-KJNodes which provides a Text Concatenate node that accepts multiple strings at once. Another useful one is ComfyUI-Impact-Pack which includes string utilities for face detailer workflows.
When choosing, consider: do you need to combine more than two strings? Then a multi-input node is better. Do you need to format numbers (like seeds) into strings? Use a Primitive node with a STRING type, or a custom node like Number to String. Always check the node’s documentation in the repository before installing.
Common Problems and Solutions
One frequent issue: the String Function node’s replace operation seems to do nothing. This happens because the node only has two visible inputs, but replace requires a third argument (the replacement text). To fix it, look for a small gear icon on the node to add a third input, or switch to a custom node like Text Replace from KJNodes.
Another problem: the output of a string function is not accepted by a node that expects a prompt. This usually means the output type is not exactly STRING. Check the node’s output type—some custom nodes output a STRING but with a different internal type (like COMBO). Convert it using a Primitive node set to string, or use a Convert String node if available.
Also, be mindful of whitespace. Concatenating two strings with spaces requires you to include the space in one of the inputs, e.g., “hello ” + “world”. Many users forget this and get “helloworld”.
String Functions vs. Python Script Nodes
If you know Python, you can bypass the limited string nodes entirely by using a Python Script node (available in some custom packs, or via the ComfyUI-Python-Nodes). This allows you to write any Python string operation, like f"{prompt} with {style}" or using re.sub(). The trade-off: you need to set up the node’s inputs and outputs manually, and the node runs on every queue execution, which can slow down if you do heavy processing. For simple tasks, the built-in function is faster and more visual.
Costs and Performance Considerations
String functions are pure text operations—they don’t affect the image generation speed or VRAM usage. They run in milliseconds. However, if you use a Python script node that performs complex regex or loops, it could add a tiny overhead, but it’s negligible compared to the model inference time. There are no monetary costs; ComfyUI is free and open-source. The only “cost” is the time to learn the node system and possibly install custom nodes.
Frequently Asked Questions
How do I concatenate more than two strings in ComfyUI? Use the String Function node multiple times (chain them), or install a custom node like Text Concatenate from KJNodes that accepts multiple inputs. You can also use a Text Multiline node and write all the text in one field, but that doesn’t allow dynamic insertion.
Can I use regular expressions in string functions? The built-in node does not support regex. You need a custom node or a Python Script node. For example, use the re.sub() function in a Python node to replace patterns.
Why does my string function output show as an error? Check that both inputs are connected and have the correct type (STRING). If you’re using a node that outputs a number, convert it to string first using a Primitive node or a Number to String node. Also, ensure the operation you selected is valid for the inputs (e.g., length expects a string).
Is there a way to format a string with placeholders like “{seed}”? The default nodes don’t support format strings. You can use a Python Script node with f"..." or .format(). Alternatively, use a custom node like Format String from ComfyUI-Custom-Scripts, which provides a format operation with named placeholders.
Can I save the output of a string function to a file? Yes, you can connect the string output to a Save Text node (if you have one) or use a Preview Text node to see it. Some custom nodes allow writing to a file directly, but that’s not a core feature.
What’s the difference between String Function and Text Multiline? Text Multiline is simply a text input box where you type or paste text; it doesn’t perform operations. String Function takes two inputs and applies an operation. You can connect a Text Multiline to a String Function to use its content in an operation.
Related
- MS Access: How to Split a Database for Multiple Users
- Java String Length: How the length() Method Really Works
- Split in JavaScript Arrays: Methods and Examples
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- Excell Battery Canada: How to Find the Right BatteryIf you are searching for an Excell battery in Canada, first check whether the name on the product…
- SQL Server REPLACE Function: Syntax and ExamplesSQL Server’s REPLACE(string_expression, string_pattern, string_replacement) function replaces every occurrence of one string with another and returns the revised…
- How to Get a Sequence Number in Excel AutomaticallyTo create a simple sequence number in Excel, enter a formula in the first numbering cell and fill…
- Excel Formula for Time Between DatesTo find the time between two dates in Excel, subtract the earlier date or date-time from the later…
- Excel DATEDIF Age Formula: Calculate Years, Months & DaysTo calculate someone’s age in completed years in Excel, enter their birth date in A2 and use =DATEDIF(A2,TODAY(),"Y").…
- TEXTJOIN Formula in Excel With FILTER: How It WorksTo join only the values that meet a condition, combine Excel’s TEXTJOIN and FILTER functions. With names in…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.