This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v20 R7
Split string

Split string 


 

Split string ( stringToSplit ; separator {; options} ) -> Function result 
Parameter Type   Description
stringToSplit  Text in String value
separator  Text in String at which stringToSplit splits. If empty string (""), each character of stringToSplit is a substring
options  Longint in Option(s) regarding empty strings and spaces
Function result  Collection in Collection of substrings

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 Longint 1 Remove empty strings from the resulting collection (they are ignored)
sk trim spaces Longint 2 Trim space characters at the beginning and end of substrings

 C_TEXT($vt)
 C_COLLECTION($col)
 $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"]

The separator parameter can be a multiple-character string:

 C_TEXT($vt)
 C_COLLECTION($col)
 $vt:="Name<tab>Smith<tab>age<tab>40"
 $col:=Split string($vt;"<tab>")
  //$col=["Name","Smith","age","40"]



See also 

TEXT TO ARRAY

 
PROPERTIES 

Product: 4D
Theme: String
Number: 1554

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v16 R6

 
ARTICLE USAGE

4D Language Reference ( 4D v20 R7)