String Manipulation Functions
AMPS provides the SUBSTR
function, that can be used for returning a subset of a string. There are two forms of this function.
The first form takes the source string and the position at which to begin the substring. You can use a negative number to count backward from the end of the string. AMPS returns a string that starts at the specified position and goes to the end of the string. If the provided position is before the beginning of the string, AMPS starts at the beginning of the string, returning the full string. If the provided position is past the end of the string, AMPS returns a zero-length string, which evaluates to NULL
.
For example, the following expressions are all TRUE
:
The second form of SUBSTR
takes the source string, the position at which to begin the substring, and the length of the substring. Notice that SUBSTR
considers the first character in the string to be position 1
(rather than position 0
), as demonstrated below. AMPS will not return a string larger than the source string. As with the two-argument form, if the starting position is before the beginning of the string, AMPS starts at the beginning of the string. If the starting position is after the end of the source string, AMPS returns an empty string which evaluates to NULL
.
For example, the following expressions are all true:
AMPS also provides simplified forms of SUBSTR
, which simply take the leftmost or rightmost characters from a string. For example, the following expressions all evaluate as true:
AMPS provides a set of functions that work with whitespace or other delimiter characters. For example, the following expressions are all true:
These functions accept an optional second parameter that specifies the delimiters to remove:
The REVERSE
function simply reverses the input string:
Last updated