String Functions
ObjectScript also provides functions for use with strings. The example demonstrates several functions which are similar to those found in other languages.
-
$Length returns the length of a string.
-
$Extract returns a substring of a string, based on a starting and ending position. You can use an asterisk (*) to represent the last character's position, and *-n to count backwards from the end.
-
$Find searches for a substring of a string, and returns the position of the character following the substring.
-
$Piece looks at a string as a series of pieces, based on a delimiter, and returns a specific piece.
-
$Justify returns a string of a specified length, padded on the left with spaces (right-justified), and/or also rounds to a specified number of decimal places.
SAMPLES>write $length("how long is this?")
17
SAMPLES>write $extract("there's gold in them hills", 9, 12)
gold
SAMPLES>write $extract("there's gold in them hills", *-4, *)
hills
SAMPLES>write $find("there's gold in them hills", "gold")
13
SAMPLES>write $piece("slice of pizza", " ", 3)
pizza
SAMPLES>write $justify(3.1415, 10, 3)
3.142
SAMPLES>
Each of these functions also has alternate forms; check the Caché documentation for the details.