This section highlights some of the most commonly used system functions in ObjectScript.
The names of these functions are not case-sensitive.
You can use the following functions to choose a value, given some input:
compares a given test expression to a set of comparison values and then returns the return value associated with the matching comparison value. For example:
examines a set of expressions and returns the return value associated with the first true expression. For example:
SAMPLES>write $SELECT(myvar=0:"branch A",1=1:"branch B")
You can use the following functions to test for the existence of a variable or of a node of a variable.
To test if a specific variable exists, use the $DATA
For a variable that contains multiple nodes, this function can indicate whether a given node exists, and whether a given node has a value and child nodes.
To get the value of a variable (if it exists) or get a default value (if not), use the $GET
ObjectScript provides a native list format. You can use the following functions to create and work with these lists:
returns a special kind of string called a list
. Sometimes this is called $LIST format
, to distinguish this kind of list from other kinds (such as comma-separated lists).
The only supported way to work with a $LIST
list is to use the ObjectScript list functions. The internal structure of this kind of list is not documented and is subject to change without notice.
returns a list element or can be used to replace a list element.
returns the position of a given element, in a given list.
There are additional list functions as well.
If you use a list function with a value that is not a list, you receive the <LIST> error.
ObjectScript also has an extensive set of functions for using strings efficiently:
returns or replaces a substring, using a character count.
finds a substring by value and returns an integer specifying its end position in the string.
returns a right-justified string, padded on the left with spaces.
converts a string from one form to another. It supports both case translations (to uppercase, to lowercase, or to title case) and encoding translation (between various character encoding styles).
modifies the given string by performing a character-by-character replacement.
performs string-by-string replacement within a string and returns a new string.
returns a substring from a character-delimited string (often called a pieced string
). Many older applications use character-delimited strings as a convenient format to contain related values, each of which is a substring within the larger string. The large string acts as a record, and the substrings are its fields.
In many cases, the delimiter is a caret. Thus in existing code, you might see pieced strings like this: "value 1^value 2^value 3"
The following demonstrates how to extract a substring:
SET mystring="value 1^value 2^value 3"
returns the number of characters in a specified string or the number of delimited substrings in a specified string, depending on the parameters used.
SET mystring="value 1^value 2^value 3"
WRITE !, "Number of characters in this string: "
WRITE !, "Number of pieces in this string: "
Working with Multidimensional Arrays
You can use the following functions to work with a multidimensional array as a whole:
allows you to sequentially visit each node within a multidimensional array.
enables you to visit every node and subnode within an array, moving up and down over subnodes.
To work with an individual node in an array, you can use any of the functions described previously. In particular:
can indicate whether a given node exists and whether a given node has child nodes.
gets the value of a given node or gets a default value otherwise.
Sometimes when you create a string, you need to include characters that cannot be typed. For these, you use $CHAR
Given an integer, $CHAR
returns the corresponding ASCII or Unicode character. Common uses:
The function $ASCII
returns the ASCII value of the given character.