ComfyUI  >  Nodes  >  ComfyUI-Chibi-Nodes >  TextSplit

ComfyUI Node: TextSplit

Class Name

TextSplit

Category
Chibi-Nodes/Text
Author
chibiace (Account age: 2903 days)
Extension
ComfyUI-Chibi-Nodes
Latest Updated
7/29/2024
Github Stars
0.0K

How to Install ComfyUI-Chibi-Nodes

Install this extension via the ComfyUI Manager by searching for  ComfyUI-Chibi-Nodes
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter ComfyUI-Chibi-Nodes in the search bar
After installation, click the  Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • High-speed GPU machines
  • 200+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 50+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

TextSplit Description

Divide text into two parts based on a separator for independent processing or analysis.

TextSplit:

The TextSplit node is designed to help you divide a given text into two parts based on a specified separator. This can be particularly useful when you need to process or analyze different sections of a text independently. The node offers flexibility in how the text is split, allowing you to choose whether to split from the start or the end of the text and which half of the split text to return. This functionality can be beneficial for tasks such as text preprocessing, data cleaning, or any scenario where managing text segments separately is required.

TextSplit Input Parameters:

text

This parameter represents the input text that you want to split. It is a string and is required for the node to function. The text will be divided based on the specified separator. The default value is an empty string, and it is mandatory to provide an input for this parameter.

separator

The separator is a string that determines where the text will be split. By default, the separator is set to a period ("."). You can customize this to any character or string that suits your needs. The choice of separator directly impacts how the text is divided into two parts.

reverse

This boolean parameter allows you to choose the direction of the split. If set to True, the text will be split from the end (rightmost occurrence of the separator). If set to False, the text will be split from the start (leftmost occurrence of the separator). The default value is False.

return_half

This parameter specifies which half of the split text to return. It offers two options: "First Half" and "Second Half". Depending on your selection, the node will return either the part of the text before the separator or the part after the separator. This allows you to focus on the specific segment of the text that is most relevant to your task.

TextSplit Output Parameters:

text

The output parameter is a string that contains the selected half of the split text. Depending on the return_half parameter, this will either be the portion of the text before or after the specified separator. This output is essential for further processing or analysis of the text segment.

TextSplit Usage Tips:

  • To split a sentence into two parts based on the first occurrence of a comma, set the separator parameter to "," and return_half to either "First Half" or "Second Half" depending on which part you need.
  • If you need to split a text from the last occurrence of a specific word, set the reverse parameter to True and provide the word as the separator.
  • Use the return_half parameter to easily extract the beginning or ending part of a text, which can be useful for tasks like extracting the main content or the conclusion of a paragraph.

TextSplit Common Errors and Solutions:

"IndexError: list index out of range"

  • Explanation: This error occurs when the specified separator is not found in the text, resulting in an unsuccessful split operation.
  • Solution: Ensure that the separator exists within the text. You can add a check to verify the presence of the separator before attempting to split the text.

"TypeError: expected string or bytes-like object"

  • Explanation: This error happens when the input text is not a string.
  • Solution: Make sure that the text parameter is provided as a string. Convert any non-string input to a string before passing it to the node.

"ValueError: too many values to unpack"

  • Explanation: This error can occur if the text contains multiple instances of the separator and the reverse parameter is not set correctly.
  • Solution: Adjust the reverse parameter to control the direction of the split, ensuring it matches the intended use case.

TextSplit Related Nodes

Go back to the extension to check out more related nodes.
ComfyUI-Chibi-Nodes
RunComfy

© Copyright 2024 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals.