Text Splitting
Text splitting functions are useful for advanced codes that deal with multiple user arguments, or even adjusting function outputs (for advanced users). This wiki includes information on how to use these functions.
Functions
There are 7 functions in this guide. One of them, $textSplit
, is the main function that you start off.
$textSplit
This function separates the text with a separator and saves the text for later use.
Syntax
$textSplit[separatedText;separator]
Parameters
separatedText
- The text separated by a separator.separator
- The separator that separates the text.
Example
$textSplit[hello-world-!;-]
$splitText
Each separated text has a number, i.e. an index. $splitText
is a function that returns one of the elements of the separated text by an index or the sign <
- the very first element, or >
- the very last element.
Syntax
$splitText[index]
Parameters
index
- The index of the element to be returned.
Examples
Example #1
$textSplit[hello-world-!;-]
The 1st element: $splitText[1]
The 2nd element: $splitText[2]
The 3rd element: $splitText[3]
Example #2
$textSplit[hello-world-!;-]
The very first element: $splitText[<]
The very last element: $splitText[>]
$getTextSplitLength
This function has a simple purpose: $getTextSplitLength
returns the length of the separated text, that is, the number of words separated by a separator. The returned value is the maximum index for the given separated text.
Syntax
$getTextSplitLength
Example
$textSplit[hello-world-!;-]
The maximum index: $getTextSplitLength
$getTextSplitIndex
This function searches for the specified element in the separated text and returns its index. If the specified element wasn't found or doesn't exist, the function will return -1
.
Syntax
$getTextSplitIndex[value]
Parameters
value
- The text, that is, the element whose index is should be returned.
Example
$textSplit[hello-world-!;-]
$onlyIf[$getTextSplitIndex[$message]!=-1;The specified element wasn't found or doesn't exist!]
The index of the specified element: $getTextSplitIndex[$message]
$joinSplitText
This function returns the current elements of the separated text with the specified (sometimes new) separator.
Syntax
$joinSplitText[separator]
Parameters
separator
- (The new) separator with which the elements should be returned.
Example
See example below, using $removeSplitTextElement or $editSplitText.
$removeSplitTextElement
This function removes an element from the separated text by the specified index.
Syntax
$removeSplitTextElement[index]
Parameters
index
- The index of the element to be removed.
Example
$textSplit[hello-world-!;-]
$onlyIf[$getTextSplitIndex[$message]!=-1;The specified element wasn't found or doesn't exist!]
$removeSplitTextElement[$getTextSplitIndex[$message]]
Successfully removed element with index $getTextSplitIndex[$message]!
Current elements: $joinSplitText[-]
$editSplitText
This function replaces the element at the specified index with a new element instead of the previous one.
Syntax
$editSplitText[index;value]
Parameters
index
- The index of the element to be replaced.value
- The text, that is, what will replace the specified element.
Example
$textSplit[hello-world-!;-]
$onlyIf[$getTextSplitIndex[$message[1]]!=-1;The specified element wasn't found or doesn't exist!]
$editSplitText[$getTextSplitIndex[$message[1]];$message[2]]
The element with index $getTextSplitIndex[$message[1]] has been replaced by $message[2]!
Current elements: $joinSplitText[-]