Script Function: Splits a string to several parts using a separator.
STR_SPLIT(String, Separator)
Syntax |
Description/Format |
---|---|
String |
The string that should be split. |
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. |
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.
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. |
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. |
Script Elements - Activation Data
About Scripts
Script Elements - Alphabetical Listing
Script Elements - Ordered by Functions