Text Operations
In ComfyUI, text is mainly handled as prompts.
Automating some operations, such as replacing part of a string or attaching trigger words to prompts created by LLMs, makes the workflow more convenient.
What is a string?
In the programming world, text is called string to distinguish it from numbers and the like.
apple → 5-character string
123 → Looks like a number, but is actually a string treated as text
" " (Space) → Invisible, but a 1-character string
Basic Operation Nodes
String Node (Text Input)
This is a basic node for entering character strings.
Using the String (Multiline) node allows you to enter text containing line breaks.
Concatenate Node (Text Joining)
Combines multiple strings into one.
(Example: apple + pen → applepen)
delimiter is a separator character. You can use whatever you like (comma, line break, etc.).
Format Text Node
{
"id": "e7ac41a3-a6f4-4793-b5e9-ff15f104192c",
"revision": 0,
"last_node_id": 4,
"last_link_id": 5,
"nodes": [
{
"id": 3,
"type": "PrimitiveString",
"pos": [
1120.168561094031,
268.47862109943014
],
"size": [
270,
58
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": [
4
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveString"
},
"widgets_values": [
"apple"
]
},
{
"id": 2,
"type": "PrimitiveString",
"pos": [
1120.168561094031,
140.8191716363399
],
"size": [
270,
58
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": [
2
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveString"
},
"widgets_values": [
"pineapple"
]
},
{
"id": 4,
"type": "PreviewAny",
"pos": [
1787.9218052801998,
140.8191716363399
],
"size": [
271.4220745373427,
189.4176425797109
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 5
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
null
]
},
{
"id": 1,
"type": "StringFormat",
"pos": [
1432.1886403621404,
140.8191716363399
],
"size": [
313.71308564995,
189.4176425797109
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"label": "a",
"name": "values.a",
"shape": 7,
"type": "*",
"link": 2
},
{
"label": "b",
"name": "values.b",
"shape": 7,
"type": "*",
"link": 4
},
{
"label": "c",
"name": "values.c",
"shape": 7,
"type": "*",
"link": null
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": [
5
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "StringFormat"
},
"widgets_values": [
"pen {a}, {b} pen"
],
"color": "#232",
"bgcolor": "#353"
}
],
"links": [
[
2,
2,
0,
1,
0,
"STRING"
],
[
4,
3,
0,
1,
1,
"STRING"
],
[
5,
1,
0,
4,
0,
"STRING"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 1.228459735736726,
"offset": [
-842.0589322707493,
177.57736449068497
]
},
"frontendVersion": "1.44.19"
},
"version": 0.4
}
This node lets you create a text template and insert other strings into it.
It can combine text more flexibly than Concatenate.
For example, if you connect apple to a and red to b, then write {a} is {b}. in format, it creates a string like apple is red..
Replace Node (Text Replacement)
Replaces specified characters with other characters.
(Example: apple pen → orange pen)
Substring Node (Text Extraction)
Extracts characters in a specified range.
(Example: apple → ppl)
- Extracts the string from the
startth to the endth character.
Trim Node (Remove Spaces)
Removes spaces before and after the string.
(Example: apple → apple)
- It is plain but important because it prevents errors caused by unintended spaces in user input etc.
Length Node (Character Count)
Counts the length of the text.
(Example: apple → 5)
- Spaces and line breaks are also counted as 1 character.
- The output will be int type (number).
Advanced Operations (Regular Expressions)
Performs complex searches and replacements using a description rule called "Regular Expression (Regex)".
Regex Extract Node
Extracts strings that match the condition using regular expressions.
Regex Replace Node
Replaces strings that match the condition using regular expressions.
Power Puter (rgthree)
The Power Puter from rgthree-comfy used in Simple Math can also input/output strings, so you can manipulate strings flexibly including the text processing mentioned above.
Power_Puter_(rgthree)_Replace.json
{
"id": "dc1f9613-0a4c-46fb-ae08-9962d0e06147",
"revision": 0,
"last_node_id": 15,
"last_link_id": 13,
"nodes": [
{
"id": 3,
"type": "PreviewAny",
"pos": [
2010.7783203125,
740.6680297851562
],
"size": [
210,
122.44491577148438
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 10
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.59",
"Node name for S&R": "PreviewAny"
},
"widgets_values": []
},
{
"id": 13,
"type": "PrimitiveString",
"pos": [
1447.3487548828125,
924.7716674804688
],
"size": [
210,
58
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": [
11
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.59",
"Node name for S&R": "PrimitiveString"
},
"widgets_values": [
"apple"
]
},
{
"id": 15,
"type": "PrimitiveStringMultiline",
"pos": [
1382.8033447265625,
740.6680297851562
],
"size": [
274.5454406738281,
121.81818389892578
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": [
13
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.59",
"Node name for S&R": "PrimitiveStringMultiline"
},
"widgets_values": [
"apple pen"
]
},
{
"id": 14,
"type": "PrimitiveString",
"pos": [
1447.3487548828125,
1045.05712890625
],
"size": [
210,
58
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": [
12
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.59",
"Node name for S&R": "PrimitiveString"
},
"widgets_values": [
"pineapple"
]
},
{
"id": 11,
"type": "Power Puter (rgthree)",
"pos": [
1703.1837158203125,
740.6680297851562
],
"size": [
261.7596435546875,
176
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "a",
"type": "*",
"link": 13
},
{
"name": "b",
"type": "*",
"link": 11
},
{
"name": "c",
"type": "*",
"link": 12
},
{
"name": "d",
"type": "*",
"link": null
}
],
"outputs": [
{
"label": "STRING",
"name": "*",
"shape": 3,
"type": "STRING",
"links": [
10
]
}
],
"properties": {
"cnr_id": "rgthree-comfy",
"ver": "0fb1e239a903e93ef626a8c20589b38f46e39dff"
},
"widgets_values": [
{
"outputs": [
"STRING"
]
},
"return a.replace(b, c)"
],
"color": "#232",
"bgcolor": "#353"
}
],
"links": [
[
10,
11,
0,
3,
0,
"*"
],
[
11,
13,
0,
11,
1,
"*"
],
[
12,
14,
0,
11,
2,
"*"
],
[
13,
15,
0,
11,
0,
"*"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 1.4641000000000008,
"offset": [
-1282.8033447265625,
-640.6680297851562
]
},
"frontendVersion": "1.27.5",
"VHS_latentpreview": false,
"VHS_latentpreviewrate": 0,
"VHS_MetadataImage": true,
"VHS_KeepIntermediate": true
},
"version": 0.4
}