Back to Home
$getTextSplitLength
$getTextSplitLength returns the total number of elements in
the current text split. Use it after $textSplit to know how
many pieces the string was broken into.
Syntax
$getTextSplitLength
No parameters. It reads whatever split is currently stored in memory.
What happens
-
$textSplitcreates the split and stores the elements. -
$getTextSplitLengthcounts those elements and returns the number.
Example 1: Count words in a message
$nomention
$textSplit[$message; ]
Word count: $getTextSplitLength
What happens:
$textSplitsplits the user's message by spaces.$getTextSplitLengthreturns the number of words.
If the user runs !example hello world !:
Word count: 3
Example 2: Use the length to reach the last element
$nomention
$textSplit[one-two-three-four;-]
Last: $splitText[$getTextSplitLength]
What happens:
$textSplitsplits the string into four elements.-
$getTextSplitLengthreturns4, which is passed directly into$splitText. $splitText[4]returns the fourth element.
Output:
Last: four
Common uses
- Counting words in a message
-
Counting characters when using an empty separator
with
$textSplit - Validation: checking whether the user provided the right number of arguments
See also
- $textSplit: must be called first to create the split
- $splitText: to read elements by index
- $joinSplitText: to reassemble the elements into a string