arrayelement(
TEXT
,
POSITION
,
SEPARATOR
)

The arrayelement( function converts between character positions and array element numbers in a text array.


Parameters

This function has three parameters:

text – is the text array that you are working with.

position – is the position of the character within the overall text (starting with 1 for the first character).

separator – is the separator character or characters for this array.


Description

The arrayelement( function converts between character positions and array element numbers in a text array (see Text Arrays). Given a character position within the overall text, the arrayelement( function tells what array element the character is in. For example, in the array red;blue;green the 7th character (u) is in the 2nd array element. If the position corresponds to a separator character, the function will return the element number of the data element to the right of the separator. If the specified position is past the end of the entire array the function will return an element number past the end of the array. This allows you to safely combine the arrayelement( function with the arrayrange( function to limit the size of an array to a certain number of characters without cutting off any individual array elements.

arrayelement("alpha/bravo/charlie",1,"/") ☞ 1
arrayelement("alpha/bravo/charlie",3,"/") ☞ 1
arrayelement("alpha/bravo/charlie",6,"/") ☞ 2
arrayelement("alpha/bravo/charlie",10,"/") ☞ 2
arrayelement("alpha/bravo/charlie",15,"/") ☞ 3
arrayelement("alpha/bravo/charlie",25,"/") ☞ 26

You can combine this function with the arrayrange( function to limit the size of an array to a certain number of characters without cutting off any individual array elements. These examples cut off the array so that it is no longer than the specified length, but make sure that only complete array elements are included.

local names
names="alpha/bravo/charlie"
arrayrange(names,1,arrayelement(names,10,"/")-1,"/") ☞ alpha
arrayrange(names,1,arrayelement(names,12,"/")-1,"/") ☞ alpha/bravo
arrayrange(names,1,arrayelement(names,20,"/")-1,"/") ☞ alpha/bravo/charlie

Error Messages

array( function: ARRAY parameter must be text. – The array (first parameter) must be text, not a number.

array( function: POSITION parameter must be numeric. – The item (second parameter) must be a number, not text.

array( function: SEPARATOR parameter must be text. – The separator character (third parameter) must be text, not a number.


See Also


History

VersionStatusNotes
10.0UpdatedCarried over from Panorama 6.0 but more than one character is now allowed for use as the separator parameter.