ELEMENT

The ELEMENT function returns a single element from a string of delimiter separated elements.

Function Name

ELEMENT

Description

Returns a single element from a string of delimiter separated elements.

Arguments

ELEMENT(ELEMENT NUMBER, 'DELIMITER', 'STRING', DIRECTION)

Where:

  • ELEMENT NUMBER is a numerical expression (INTEGER) that specifies the number of the element that is to be extracted from the STRING of delimiter separated elements. 1 for the first element, 2 for the second element, and so on.

    If the value is 0 or negative, an empty string is returned.

    If the value exceeds the number of elements in the string, the DELIMITER is returned.

  • DELIMITER is a string expression that indicates the delimiter that is being used to separate the individual elements in the STRING of delimiter separated elements. If the delimiter is a string literal, enclose it within single quotation marks. For more information, see String
  • STRING is the string expression in which to search. The individual elements that form the string must be separated from each other using the specified DELIMITER. If this string is a string literal, enclose it within single quotation marks. (If you intend using a string literal here, also consider whether to use the LOOKUP function instead of the ELEMENT function.)
  • DIRECTION is a numerical expression (INTEGER) that indicates the direction in which the STRING is to be searched. 0 indicates that the search is to start from the left; with another value the search starts from the right.
Returns

STRING

The function returns the specified single element from the list of delimiter separated elements.

Example:

An expression to return the first element of a comma delimited string:

ELEMENT( 1, ',', 'Good,Bad,Failed', 0 )

The 1 indicates that the first element is to be extracted from the left direction (0) of the comma delimited string in which the string elements are separated by a comma (','). This results in the expression returning the string Good.

To return the last element from the same comma delimited string, you would change the last argument from a 0 to a 1 (to denote that the required string is to be extracted from the right side of the comma delimited string):

ELEMENT( 1, ',', 'Good,Bad,Failed', 1 )

This expression returns the string Failed.


Disclaimer

Geo SCADA Expert 2020