Skip to main content

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?")
SAMPLES>write $extract("there's gold in them hills", 9, 12)
SAMPLES>write $extract("there's gold in them hills", *-4, *)
SAMPLES>write $find("there's gold in them hills", "gold")
SAMPLES>write $piece("slice of pizza", " ", 3)
SAMPLES>write $justify(3.1415, 10, 3)

Each of these functions also has alternate forms; check the Caché documentation for the details.

FeedbackOpens in a new tab