Automation Engine Script Guide > Ordered by Function > Strings > STR_SPLIT

STR_SPLIT

Script Function: Splits a string to several parts using a separator.

Syntax 

STR_SPLIT(String, Separator)

Syntax

Description/Format

String

The string that should be split.
Format: script literal or script variable

Separator This can be any character of your choice.
Format: AE-Name, script literal or script variable

Return codes

Array that includes the individual partial strings.

Comments

This script function splits the specified String to several partial strings by using a certain Separator. The result is an array that stores the individual strings.

The result does not include the separator.

When multiple separator characters are used in a row, the STR_SPLIT script function creates empty strings for the second separator and all subsequent separators.

When a string begins with one or more separator characters, the STR_SPLIT script function creates empty strings for them.

To store the result, you define a script array using :DEFINE and then you use the script element :FILL. Make sure that you use the data type "String" when you define the array.

Examples

The following example splits the string "123_456_789" as specified with the separator "_" and stores the result in a string array. The individual array elements are then written to the activation report.

:DEFINE &STRINGS#, string, 5
:SET &STRING#"123_456_789"
:FILL &STRINGS#[] = STR_SPLIT(&STRING#,"_")




:SET &VAR# = 1
:SET &LEN# = LENGTH(&STRINGS#[])

:WHILE &VAR# LE &LEN#
:SET &VAR#FORMAT(&VAR#,"0")
:PRINT "&VAR#. Partial string = &STRINGS#[&VAR#]"
:SET &VAR# = &VAR#+ 1
:ENDWHILE

Output in the activation protocol:

2013-10-23 10:30:48 - U0020408 1. Partial string = 123

2013-10-23 10:30:48 - U0020408 2. Partial string = 456

2013-10-23 10:30:48 - U0020408 3. Partial string = 789

2013-10-23 10:30:48 - U0020408 4. Partial string =

2013-10-23 10:30:48 - U0020408 5. Partial string =

 

See also:

Script element Description
:DEFINE Declares a script variable with a particular data type.

:FILL

Stores several values to a script array.

:PUBLISH Defines script variables and arrays as object variables.
STR_PAD Extends a string to a certain length.