Skip to main content
Version: 20 R7 BETA

Split string

Split string ( stringToSplit ; separator {; options} ) : Collection

ParameterTypeDescription
stringToSplitTextString value
separatorTextString at which stringToSplit splits. If empty string (""), each character of stringToSplit is a substring
optionsIntegerOption(s) regarding empty strings and spaces
Function resultCollectionCollection 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:

ConstantTypeValueComment
sk ignore empty stringsInteger1Remove empty strings from the resulting collection (they are ignored)
sk trim spacesInteger2Trim 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

TEXT TO ARRAY

Properties

Command number1554
Thread safe