Split string
Split string ( stringToSplit ; separator {; options} ) : Collection
Parameter | Type | Description | |
---|---|---|---|
stringToSplit | Text | → | String value |
separator | Text | → | String at which stringToSplit splits. If empty string (""), each character of stringToSplit is a substring |
options | Integer | → | Option(s) regarding empty strings and spaces |
Function result | Collection | ← | Collection of substrings |
Description
The Split string command returns a collection of strings, created by splitting stringToSplit into substrings at the boundaries specified by the separator parameter. The substrings in the returned collection do not include separator itself.
If no separator is found in stringToSplit, Split string returns a collection containing a single element, stringToSplit. If you passed an empty string in separator, Split string returns a collection of each character of stringToSplit.
In the options parameter, you can pass one or a combination of the following constants from the Strings theme:
Constant | Type | Value | Comment |
---|---|---|---|
sk ignore empty strings | Integer | 1 | Remove empty strings from the resulting collection (they are ignored) |
sk trim spaces | Integer | 2 | Trim space characters at the beginning and end of substrings |
Example 1
var $vt : Text
var $col : Collection
$col:=New collection
$vt:="John;Doe;120 jefferson st.;Riverside;; NJ; 08075"
$col:=Split string($vt;";") //["John","Doe","120 jefferson st.","Riverside",""," NJ"," 08075"]
$col:=Split string($vt;";";sk ignore empty strings) //["John","Doe","120 jefferson st.","Riverside"," NJ"," 08075"]
$col:=Split string($vt;";";sk ignore empty strings+sk trim spaces) //["John","Doe","120 jefferson st.","Riverside","NJ","08075"]
Example 2
The separator parameter can be a multiple-character string:
var $vt : Text
var $col : Collection
$vt:="NameSmithage40"
$col:=Split string($vt;"")
//$col=["Name","Smith","age","40"]
See also
Properties
Command number | 1554 |
Thread safe | ✓ |