Back to Home
$splitText
$splitText returns a single element from the current text
split by its index. You always call $textSplit first to
create the split, then use $splitText to read one of the
pieces.
Syntax
$splitText[Index]
-
Index: the position of the element to return. Must be a positive integer,<, or>. <returns the first element.>returns the last element.-
A number (e.g.
2) returns the element at that position.
What happens
-
$textSplitcreates the split and stores the elements. -
$splitText[Index]looks up the element at the given position and returns it.
Indexes start at 1. If you split
hello world ! by spaces, index 1 is
hello, index 2 is world, and
index 3 is !.
Example 1: Get a specific element
$nomention
$textSplit[hello world !; ]
$splitText[2]
What happens:
-
$textSplitsplitshello world !by spaces into three elements. $splitText[2]returns the second one.
Output:
world
Example 2: First and last shortcuts
$nomention
$textSplit[hello world !; ]
> $splitText[<]
> $splitText[>]
What happens:
-
$textSplitsplits the string intohello,world,!. $splitText[<]returns the first element.$splitText[>]returns the last element.
Output:
> hello
> !
Common uses
-
Reading command arguments:
$splitText[1]for the first argument,$splitText[2]for the second - Getting the first or last item from a list without knowing its full length
- Looping through elements by incrementing the index
See also
- $textSplit: must be called first to create the split
- $getTextSplitLength: to find out how many elements exist
- $getTextSplitIndex: to find the index of a specific value