ComfyUI Node

String Split

Cut a string into two pieces at a delimiter

By jamesWalker55·Created 3 years ago·Updated about a year ago· 217
String Split
    • STRING
    • STRING
    sourcea,b
    split_by,
    from_right

    Takes a string, finds a delimiter you specify, and breaks the string into two pieces there - the part before and the part after. Give it key: value and split on :, and you get key out of one socket and value out of the other. It's the "chop this text in two" node.

    You'd use it to pull structured text apart: separate a filename from its extension, grab the label before a colon, split a coordinate pair, peel a prefix off a string. In workflows that pass around text - dynamic prompts, parsed filenames, values assembled elsewhere - this is how you get at one half of it.

    How it works

    It splits on the delimiter into two parts. By default it splits on the first occurrence; flip from_right and it splits on the last one instead. The two halves come out of the two string outputs.

    Inputs and outputs

    • source - the string to split.
    • split_by - the delimiter to split on (default ,). Can be any string, not just a single character.
    • from_right - false splits at the first occurrence of the delimiter, true splits at the last. This matters when the delimiter appears more than once (more on that below).

    Two STRING outputs: the piece before the delimiter and the piece after it.

    Installing it

    It's in the pack's comfyui_primitive_ops file. Install via ComfyUI Manager (search Various ComfyUI Nodes by Type / comfyui-various) or clone:

    cd ComfyUI/custom_nodes
    git clone https://github.com/jamesWalker55/comfyui-various
    

    Restart ComfyUI. No models, no extra dependencies.

    Common issues

    The behavior people forget is that this splits into exactly two pieces, at a single occurrence of the delimiter - not into a list of every segment. If your string is a,b,c,d and you split on ,, you get a and b,c,d (first occurrence) - not four separate values. That's where from_right earns its keep: for something like my.file.name.png, splitting on . from the right gives you my.file.name and png, which is exactly what you want for isolating an extension. Splitting from the left would hand you my and file.name.png instead.

    Second, mind the delimiter you're not seeing. Splitting a, b on , leaves a leading space on the second piece ( b), because the space was after the comma. If that space matters downstream, trim it - the pack's JWStringReplace can strip it.

    And decide what should happen if the delimiter isn't in the string at all, rather than being surprised by it - the safest habit is to make sure the delimiter is really there before you depend on the second output.

    If the node loads red as missing in a shared workflow, install the pack via Manager's "Install Missing Custom Nodes" or clone the repo above.

    CategoryjamesWalker55

    Inputs (3)

    NameTypeDefaultDescription
    sourceSTRINGa,b
    split_bySTRING,
    from_rightCOMBO2 options: false, true

    Outputs (2)

    NameTypeDescription
    STRINGSTRING
    STRINGSTRING