Back to Home
$textSplit
$textSplit splits a string by a given separator and stores
the resulting elements temporarily. It is always the first step, every
other text splitting function depends on this one having been called
first.
Syntax
$textSplit[Text;Separator]
Text: the string to split.-
Separator: the character or string used to divide the text. If left empty, the text is split into individual characters.
What happens
-
$textSplittakes the text you provide and breaks it apart at every occurrence of the separator. -
Each piece is stored as a numbered element, starting from index
1. -
Nothing is returned visually, the split is held in memory. Use
$splitText,$getTextSplitLength, or any other text split function to work with the result.
Example 1: Split by a separator
$nomention
$textSplit[hello-world-!;-]
$splitText[2]
What happens:
-
$textSplitsplitshello-world-!using-as the separator. -
This creates three elements:
hello(1),world(2),!(3). $splitText[2]returns the second element.
Output:
world
Example 2: Split by character (empty separator)
$nomention
$textSplit[$message;]
$getTextSplitLength
What happens:
-
The empty separator causes
$textSplitto split every character individually. -
$getTextSplitLengthreturns the total character count.
If the user runs !example Hello:
5
Common uses
-
Parsing command arguments: split
$messageby spaces to read individual arguments - Processing lists: split comma-separated or hyphen-separated data
- Counting characters: use an empty separator to treat each character as an element
See also
- $splitText: to read a specific element from the split
- $getTextSplitLength: to count how many elements were created
- $joinSplitText: to reassemble the elements into a string