More List Functions
Additional functions for working with lists:
-
$ListValid determines whether a string is a list.
-
$ListFromString returns a list built from a delimited string.
-
$ListToString returns a delimited string built from a list.
-
$ListSame compares 2 lists item by item, and returns 1 if they are identical, 0 otherwise.
-
$ListNext advances sequentially from one list item to the next, returning 1 when it advances and 0 when it reaches the end. It also changes the values of its second and third arguments to the list position and item value at that position, respectively.
-
Set $ListBuild sets a list of variables to the items of a list. You can think of it as "un-build a list."
Terminal
USER>set addr = "One Memorial Drive", city = "Cambridge"
USER>set st = "MA", zip = "02142"
USER>set Pmail = addr _ "^" _ city _ "^" _ st _ "^" _ zip
USER>set Lmail = $listfromstring(Pmail, "^")
USER>write $listvalid(Lmail)
1
USER>write $listvalid(Pmail)
0
USER>write $list(Lmail, 2)
Cambridge
USER>write $listlength(Lmail)
4
USER>write $listfind(Lmail, "MA")
3
USER>set Pmail = $listtostring(Lmail, "*")
USER>write Pmail
One Memorial Drive*Cambridge*MA*02142
USER>set Lmail2 = $listbuild("One Memorial Drive", "Cambridge", "MA", "02141")
USER>write $listsame(Lmail, Lmail2) // not the same because of different zip
0
USER>set p = 0 while $listnext(Lmail, p, value) {write !, value}
One Memorial Drive
Cambridge
MA
02142
USER>set $listbuild(addr2, city2, st2, zip2) = Lmail2
USER>write addr2, !, city2, !, st2, !, zip2
One Memorial Drive
Cambridge
MA
02141
USER>