🔎 Variable Replace All: Replace a string array with another string array

Here, feel free to optimise this further; I’ll provide the module export below

Module Export

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the JSON code below by clicking the copy button when you mouseover the top-right of the code block
    Screenshot_2024-01-17_200117

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the canvas.

  3. Click on each imported module and save it for validation. You may be prompted to remap some variables and connections.

View Module Export Code

JSON

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 1,
                    "module": "util:SetVariables",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "variables": [
                            {
                                "name": "text",
                                "value": "Lorem ipsum test sit amet, hello adipiscing elit, sed do eiusmod tempor incididunt ut labore et test magna aliqua. Ut enim ad minim hello, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea test hello. Duis aute irure test in reprehenderit in voluptate velit esse cillum test hello fugiat nulla pariatur. Excepteur sint occaecat cupidatat test proident, sunt in culpa qui officia deserunt hello anim id est hello."
                            },
                            {
                                "name": "searchArray",
                                "value": "{{split(\"test|hello\"; \"|\")}}"
                            },
                            {
                                "name": "replaceArray",
                                "value": "{{split(\"SUCCESS|GOODBYE\"; \"|\")}}"
                            }
                        ],
                        "scope": "roundtrip"
                    },
                    "metadata": {
                        "designer": {
                            "x": -560,
                            "y": -128,
                            "name": "Set Text, Search, Replace vars"
                        },
                        "restore": {
                            "expect": {
                                "variables": {
                                    "items": [
                                        null,
                                        null,
                                        null
                                    ]
                                },
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "variables",
                                "type": "array",
                                "label": "Variables",
                                "spec": [
                                    {
                                        "name": "name",
                                        "label": "Variable name",
                                        "type": "text",
                                        "required": true
                                    },
                                    {
                                        "name": "value",
                                        "label": "Variable value",
                                        "type": "any"
                                    }
                                ]
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            }
                        ],
                        "interface": [
                            {
                                "name": "text",
                                "label": "text",
                                "type": "any"
                            },
                            {
                                "name": "searchArray",
                                "label": "searchArray",
                                "type": "any"
                            },
                            {
                                "name": "replaceArray",
                                "label": "replaceArray",
                                "type": "any"
                            }
                        ]
                    }
                },
                {
                    "id": 2,
                    "module": "builtin:BasicRepeater",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "step": "1",
                        "start": "1",
                        "repeats": "{{if(length(1.searchArray) = length(1.replaceArray); length(1.searchArray); null)}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -336,
                            "y": -129,
                            "name": "Replace ALL"
                        },
                        "restore": {},
                        "expect": [
                            {
                                "name": "start",
                                "type": "number",
                                "label": "Initial value",
                                "required": true
                            },
                            {
                                "name": "repeats",
                                "type": "number",
                                "label": "Repeats",
                                "required": true,
                                "validate": {
                                    "max": 10000,
                                    "min": 0
                                }
                            },
                            {
                                "name": "step",
                                "type": "number",
                                "label": "Step",
                                "required": true
                            }
                        ]
                    }
                },
                {
                    "id": 3,
                    "module": "util:GetVariable2",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "name": "text"
                    },
                    "metadata": {
                        "designer": {
                            "x": -114,
                            "y": -128,
                            "name": "Get current replaced text"
                        },
                        "restore": {},
                        "expect": [
                            {
                                "name": "name",
                                "type": "text",
                                "label": "Variable name",
                                "required": true
                            }
                        ],
                        "interface": [
                            {
                                "name": "text",
                                "type": "any",
                                "label": "text"
                            }
                        ]
                    }
                },
                {
                    "id": 4,
                    "module": "util:SetVariable2",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "name": "text",
                        "scope": "roundtrip",
                        "value": "{{replace(3.text; 1.searchArray[2.i]; 1.replaceArray[2.i])}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 109,
                            "y": -129,
                            "name": "Perform replace"
                        },
                        "restore": {
                            "expect": {
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "name",
                                "type": "text",
                                "label": "Variable name",
                                "required": true
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            },
                            {
                                "name": "value",
                                "type": "any",
                                "label": "Variable value"
                            }
                        ],
                        "interface": [
                            {
                                "name": "text",
                                "type": "any",
                                "label": "text"
                            }
                        ]
                    }
                },
                {
                    "id": 5,
                    "module": "util:TextAggregator",
                    "version": 1,
                    "parameters": {
                        "feeder": 2,
                        "rowSeparator": "other",
                        "otherRowSeparator": ""
                    },
                    "mapper": {
                        "value": "{{if(2.i != length(1.searchArray); emptystring; 4.text)}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 329,
                            "y": -128,
                            "name": "Get final replace result",
                            "messages": [
                                {
                                    "category": "last",
                                    "severity": "warning",
                                    "message": "A transformer should not be the last module in the route."
                                }
                            ]
                        },
                        "restore": {
                            "extra": {
                                "feeder": {
                                    "label": "Replace ALL"
                                }
                            },
                            "flags": {
                                "groupBy": {
                                    "collapsed": true
                                },
                                "stopIfEmpty": {
                                    "collapsed": true
                                }
                            },
                            "parameters": {
                                "rowSeparator": {
                                    "label": "Other"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "rowSeparator",
                                "type": "select",
                                "label": "Row separator",
                                "validate": {
                                    "enum": [
                                        "\n",
                                        "\t",
                                        "other"
                                    ]
                                }
                            },
                            {
                                "name": "otherRowSeparator",
                                "type": "text",
                                "label": "Separator"
                            }
                        ],
                        "expect": [
                            {
                                "name": "value",
                                "type": "text",
                                "label": "Text"
                            }
                        ],
                        "advanced": true
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

samliewrequest private consultation

Join the Make Fans Discord server to chat with makers!