Article directory
Chapter 15 ObjectScript - String Functions
String functions
ObjectScript
There is also an extensive set of functions for working with strings efficiently:
$EXTRACT
Return or replace a substring using character counting.$FIND
Finds a substring by value and returns an integer specifying its ending position in the string.$JUSTIFY
Returns a right-justified string, padded with spaces on the left.$ZCONVERT
Convert a string from one form to another. It supports case conversion (to uppercase, lowercase, or title case) and encoding conversion (between various character encoding styles).$TRANSLATE
Modifies the given string by performing character-by-character replacement.$REPLACE
Performs a string-by-string replacement in a string and returns a new string.$PIECE
Returns a substring from a character-delimited string (often called a segmented string). Here's how to extract a substring:
SET mystring="value 1^value 2^value 3"
WRITE $PIECE(mystring,"^",1)
$LENGTH
Returns the number of characters in the specified string or the number of delimited substrings in the specified string, depending on the arguments used.
SET mystring="value 1^value 2^value 3"
WRITE !, "Number of characters in this string: "
WRITE $LENGTH(mystring)
WRITE !, "Number of pieces in this string: "
WRITE $LENGTH(mystring,"^")
Use multidimensional arrays
The following functions can be used to process entire multidimensional arrays:
$ORDER
Allows sequential access to each node in a multidimensional array.$QUERY
Enables access to each node and child node in the array, and moves up and down the child nodes.
To work with a single node from an array, you can use any of the functions described previously. especially:
$DATA
Can indicate whether a given node exists and whether the given node has children.$GET
Get the value of the given node, otherwise get the default value.
Character Values
Sometimes, when creating a string, you need to include characters that cannot be typed. For these, it is possible to use $CHAR
.
Given an integer, $CHAR
return the corresponding ASCII
or Unicode
character. Common uses:
$CHAR(9)
is a tab character.$CHAR(10)
is a newline character.$CHAR(13)
It's the carriage return character.$CHAR(13,10)
It's a carriage return and line feed pair.
Function $ASCII
returns ASCII
the value of the given character.