Skip to main content
Version: 1.0.0

splitString

splitString* ( stringToSplit : string , separator : string {, options : integer }) : collection

ParameterTypeDescription
stringToSplitstringString value
separatorstringString at which stringToSplit splits. If empty string (""), each character of stringToSplit is a substring
optionsintegerOption(s) regarding empty strings and spaces
ResultcollectionCollection of substrings

Description

The splitString 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, splitString returns a collection containing a single element, stringToSplit. If you passed an empty string in separator, splitString returns a collection of each character of stringToSplit.

In the options parameter, you can pass one or a combination of the following constants:

ConstantComment
kIgnoreEmptyStringsRemove empty strings from the resulting collection (they are ignored)
kTrimSpacesTrim space characters at the beginning and end of substrings

Example 1

 var myText : string
var myCol : collection
col = newCollection

myText = "John,Doe,120 jefferson st.,Riverside,, NJ, 08075"
myCol = splitString(myText,",") //["John","Doe","120 jefferson st.","Riverside",""," NJ"," 08075"]
myCol = splitString(myText,",",kIgnoreEmptyStrings) //["John","Doe","120 jefferson st.","Riverside"," NJ"," 08075"]
myCol = splitString(myText,",",kIgnoreEmptyStrings+kTrimSpaces) //["John","Doe","120 jefferson st.","Riverside","NJ","08075"]

Example 2

The separator parameter can be a multiple-character string:

 var myText : string
var myCol : collection
myText = "Name<tab>Smith<tab>age<tab>40"
myCol = splitString(myText,"<tab>")
//myCol = ["Name","Smith","age","40"]

See also

collection.join()