ComfyUI Node

String Split

Value parser

By TakkunRed·Created 5 months ago·Updated 15 days ago· 1
String Split
    • before
    • after
    ◄text►
    ◄delimiter►
    ◄occurrence1►
    ◄use_lastfalse►

    String Split cuts a string in two at a delimiter and hands you the piece before it and the piece after it. "masterpiece, 1girl" with delimiter ", " gives you masterpiece and 1girl. It's the key:value parser of the TakkunRed ComfyUI-String-Function pack, and it's the node you reach for when text arrives as name: value, category - description, or file.txt and you need both sides as separate wires.

    The reason it beats a full regex for most jobs is that it's a binary split - two outputs, before and after - not a list explosion. If you only ever need the first segment and the rest, or the part before a marker and the part after, this is a one-node answer with nothing to count. Pair it with String Find or String Regex Match for anything more structured.

    How it works

    It finds a delimiter and splits at it, with two controls over which delimiter when there are several:

    • occurrence (default 1) - split at the Nth delimiter. occurrence=2 splits at the second , rather than the first.
    • use_last (default False) - instead of the Nth, split at the last occurrence of the delimiter. This is the classic "get the part after the final dot" move for filenames: archive.tar.gz split on . with use_last=True gives you archive.tar and gz.

    The behavior when the delimiter isn't found is deliberate and worth remembering: the whole text comes back as before, and after is empty. No error, no crash - just both outputs still defined, which keeps downstream nodes from red-lining.

    Inputs and outputs

    Required: text and delimiter. Optional: occurrence (1–999) and use_last. Outputs:

    • before (STRING) - the part up to (not including) the delimiter.
    • after (STRING) - the part after (not including) the delimiter.

    Both exclude the delimiter itself - there's no "keep the separator" mode, so if you need the delimiter preserved you'll concatenate it back in downstream.

    Installing it

    Same pack, same zero-dependency story:

    cd ComfyUI/custom_nodes
    git clone https://github.com/TakkunRed/ComfyUI-String-Function
    

    Or search "ComfyUI-String-Function" in ComfyUI Manager, restart, and it's under String Function.

    Where people get burned

    • Delimiter not found silently means "no split." The whole string lands in before and after is empty - useful, but if you expected a split to happen and it didn't, check the delimiter spelling (including the space before/after it).
    • An empty delimiter returns the text whole. The source guards this: delimiter="" gives you before=text, after="".
    • It splits at the first occurrence by default. "a,b,c" with "," gives a and b,c - the after still contains the rest of the list. If you want every piece, chain a couple of these or use String Regex Match's findall.
    • use_last ignores occurrence. They're two different ways to pick which delimiter; setting both is allowed but use_last wins. The tooltip says as much.

    For key: value parsing out of an LLM's structured output, or peeling a filename apart, it's the two-wire answer - and use_last=True is worth memorising on its own.

    CategoryString Function

    Inputs (4)

    NameTypeDefaultDescription
    textSTRING—
    delimiterSTRING—
    occurrenceoptINT11–999何番目の区切り文字で分割するか (use_last が True のときは無視)
    use_lastoptBOOLEANfalseTrue にすると最後に出現した区切り文字で分割する

    Outputs (2)

    NameTypeDescription
    beforeSTRING—
    afterSTRING—