GET_ELEMENT - Return an element a string

Help Contents

Introduction

Returns an element of a string. A delimiter character is used to mark the boundary between elements.

Syntax

Informal Syntax:

GET_ELEMENT( In, DLM, INDEX )

Formal Syntax:

GET_ELEMENT( In:=expression, DLM:=expression, INDEX:=expression )

Parameters

ParameterTypeDescription
InANY_STRINGThe input string.
DLM ANY_CHARS The delimiter used to mark the boundary between elements.
INDEX ANY_INT The index of the element to return. If INDEX >= 0, elements are counted from the start of the In parameter. If INDEX < 0, elements are counted from the end of the In parameter.

The function is overloaded and accepts either the STRING or WSTRING type for the In parameter.

Return Value

The return value is an element of the In string delimited by the DLM parameter. The INDEX parameter determines which element is returned. For example:

INDEXReturns
0The first element.
1The second element.
2The third element.
-1The last element.
-2The second to last element.

If INDEX is out of range, the DLM parameter is returned.

The type of the string returned is the same as the In parameter.

Examples

ExampleReturn Value
GET_ELEMENT("No Elements", ",", 0 )WSTRING#"No Elements"
GET_ELEMENT("No Elements", ",", 1 )WSTRING#","
GET_ELEMENT('Item1-Item2-Item3', '-', 0)STRING#'Item1'
GET_ELEMENT('Item1-Item2-Item3', '-', 2)STRING#'Item3'
GET_ELEMENT('Item1-Item2-Item3', '-', 3)STRING#'-'
GET_ELEMENT('Item1-Item2-Item3', '-', -1)STRING#'Item3'
GET_ELEMENT('Item1-Item2-Item3', '-', -2)STRING#'Item2'

Standards Compliance

The function GET_ELEMENT is an extension to the IEC 61131-3 standard.

Further Information

String Functions

To learn about other String Functions.

Common Elements

To learn about other IEC 61131-3 Common Elements.

Glossary

For the meaning of terms used in Fernhill SCADA.