str_to_lst(S;D)

Returns a list-value from a delimiter-separated string.

Function type

Scalar only

Syntax

str_to_lst(S;D)

Input

Argument Type Description
S text The string whose contents will be returned as a list-value

If S is omitted, an error is returned.

D text The character(s) used as the delimiter in string S

If D is omitted, then a comma is the default delimiter.

In cases where multiple delimiting characters are used, they are passed as a space-separated list:

D1 D2 .. Dn

where D1 delimits the highest level of the nested list structure, and Dn is the delimiter used at the level of individual values.

A scalar value

Return Value

Returns a list-value whose elements hold the delimited values contained in S.

If D is a character that does not appear in X, then the return value is a single list-value with one element.

Note: This function is scalar only. It will return an error if used in a vector context.

Sample Usage

As an example, the following function call:
minestrone="carrots,celery,onion,tomato,fusilli,beans,pancetta,kale"
grocery_list="str_to_lst(minestrone;',')"
returns a list-value where each text value between the commas is an element in the new list-value.

Example: Make a delimited string into a list-value

A string, S, with a consistent delimiting character, D, can be converted into a list-value.

<let string="How,many,unique,dimensions,are,predicted,by,Witten,in,M,theory?" delim=",">
    <willbe name="m" value="'{lst_len(str_to_lst(@string;@delim))}'"/>
</let>

The code above converts a string into a list, then returns a computed column whose value is the length of the new list-value: 11.

Example: Make a delimited string into a multi-level list

A string, S, with multiple delimiting characters, D, can be converted into a multi-level list-value.

<set list="{str_to_lst('1-2-3|4-5-6-7/a-b-c|d-e-f';'/' '|' '-')}"/>
<willbe name="z1" value="'{@x.2.1.3}'"/>

The code above produces a list called list with three levels beneath it. The first level, delimited by slashes (/), contains two list-values. The first list-value contains two lists of numbers, and the second list-value contains two lists of letters, each of which is delimited by pipe characters (|). The lists at the third level each contain the individual values, delimited by dashes (-).

The computed column z1 contains the value: c, which corresponds to the second list-value (delimited by the slash), then within that, the first list (delimited by the pipe characters), and then within that, the third value (delimited by the dashes).

A parameterized version of the same thing looks like this:
<set string="1-2-3|4-5-6-7/a-b-c|d-e-f" d1="/" d2="|" d3="-"/>
<set list="{str_to_lst(@string;@d1 @d2 @d3)}"/>
<willbe name="test" value="'{@list.2.1.3}'"/>