Skip to main content

Lists

A list is useful when you want to avoid thinking about delimiters altogether. With delimiters, there's always the chance that one of the substrings will contain the delimiter character, which will throw off the positions of the pieces in the string. Lists prevent this.

Like Piece(), List() has additional features. List() can return a list of items, rather than a single item. List() generates a <NULL VALUE> error if there's an empty piece; ListGet() returns the empty string in this case.

addr = "One Memorial Drive" : city = "Cambridge" : st = "MA" : zip = "02142"
mail = listbuild(addr, city, st, zip)
println "city = ", list(mail, 2)
println "5th (empty) item = ", listget(mail, 5)
cityst = list(mail, 2, 3)
println "state = ", list(cityst, 2)
println "count of items = ", listlength(mail)
println "MA is item #", listfind(mail, "MA")

You can't use a list function on a normal string, or you'll get a <LIST> error. Likewise, you usually will not use string functions on a list. Although you can Println a string built with ListBuild(), it's not recommended, because it contains control characters. You should access lists solely using the special list functions.

FeedbackOpens in a new tab