Documentation

Added in v3.18d

list

Syntax: %list(string, delim, stripnulls)

Forces the string to be converted to a proper string list or database variable. TeSSH normally creates string lists and database variables automatically when using the syntax {item1|item2|item3...} or {key1=value1|key2=value2...} directly with the variable assignment. However, in some cases you might have this string syntax stored in a string variable and need to create the proper array/table structure.

The optional "delim" argument can be used to convert non-standard string lists that use something other than the | character for the delimiter.

If the optional "stripnulls" argument is true (1), then null values in the list will be removed. This would allow you to treat multiple consecutive delimiters as a single delimiter.

Example

s = "item1|item2|item3"
#SHOW %json(@s)
list = %list(@s)
#SHOW %json(@list)

The first #SHOW statement shows that the variable is still a normal literal string. The second #SHOW statement shows the @list is now a proper array.

s = "word1 word2 word3"
list = %list(@s," ",1)

sets @list to an array of just 3 values. The multiple spaces are treated as a single space via the "stripnulls" argument.

Add comment

Login or register to post comments