Skip to main content

ListFromString

Creates a list from a string.

Synopsis

ListFromString(string[,delimiter])

Parameters

string A string to be converted into a Caché list. This string contains one or more elements, separated by a delimiter. The delimiter does not become part of the resulting Caché list.
delimiter Optional — The delimiter used to separate substrings (elements) in string. Specify delimiter as a quoted string. If no delimiter is specified, the default is the comma (,) character.

Description

ListFromString takes a quoted string containing delimited elements and returns a list. A list represents data in an encoded format which does not use delimiter characters. Thus a list can contain all possible characters, and is ideally suited for bitstring data. Lists are handled using the Caché Basic List functions.

A Caché list can also be created using the ListBuild function, or extracted from another list using the List function.

Parameters

string

A string literal (enclosed in quotation marks), a numeric, or a variable or expression that evaluates to a string. This string can contain one or more substrings (elements), separated by a delimiter. The string data elements must not contain the delimiter character (or string), because the delimiter character is not included in the output list.

delimiter

A character (or string of characters) used to delimit substrings within the input string. It can be a numeric or string literal (enclosed in quotation marks), the name of a variable, or an expression that evaluates to a string.

Commonly, a delimiter is a designated character which is never used within string data, but is set aside solely for use as a delimiter separating substrings. A delimiter can also be a multi-character string, the individual characters of which can be used within string data.

If you specify no delimiter, the default delimiter is the comma (,) character. You cannot specify a null string ("") as a delimiter.

Example

The following example takes a string containing names that are separated by blank spaces, and creates a list:

namestring="Deborah Noah Martha Bowie"
namelist=ListFromString(namestring," ")
Println "1st element: ",List(namelist,1)
Println "2nd element: ",List(namelist,2)
Println "3rd element: ",List(namelist,3)

The blank spaces are the string delimiter and are not included in the newly created list.

The following example takes a string containing names that are separated by a <sp> delimiter, and creates a list:

namestring="Deborah<sp>Noah<sp>Martha<sp>Bowie"
namelist=ListFromString(namestring,"<sp>")
Println "1st element: ",List(namelist,1)
Println "2nd element: ",List(namelist,2)
Println "3rd element: ",List(namelist,3)

The following example uses the default delimiter (a comma) and creates a list. Note that the second element of this list contains no value:

namestring="Deborah,,Noah,Martha"
namelist=ListFromString(namestring)
Println "1st element: ",List(namelist,1)
Println "2nd element: ",List(namelist,2)
Println "3rd element: ",List(namelist,3)

See Also

FeedbackOpens in a new tab