&SUBSTR

Extract a substring from a string, starting with startcolumn and continuing for length .
Restriction: This topic applies only when the AppMaster Builder AddPack has been installed, and applies only to Windows platforms.

Syntax:

&SUBSTR( string, startcolumn[, length])

Aliases:

&substr( string, startcolumn[, length])
&Substr( string, startcolumn[, length])

Parameters:

String Can be an alphanumeric literal string delimited with quotation marks, a number, or a variable with a string value.
Startcolumn and length Can be a number or variable; if length is omitted, the substring includes all characters from startcolumn onward.

Comments:

  • If startcolumn is greater than length, or if length is 0, the result is an empty string.
  • If startcolumn plus length is greater than length, the result begins with string start character and ends with its last character; the substring is not padded with blanks.

Examples:

Extract a substring from the string value of &PREFIX, starting with column 1 and continuing for 23 characters.

% &PREFIX = &SUBSTR( &PREFIX, 1, 23)

Extract substring values from the values of &RANDOM and &STUFF, and assign the result to MY-LANGUAGE. Note that &QT defines the delimiter character as the apostrophe; the quotation marks delimiting the string values are not considered part of the string and are stripped from the output.

Input:

% &QT = "'"
% &RANDOM = &SUBSTR( "MEANINGLESS", 1, 4)
% &STUFF = &SUBSTR( "EXAMPLE", 3, 5)
MY-LANGUAGE = &QT&RANDOM&STUFF&QT

Output:

MY-LANGUAGE = 'MEANAMPLE'

When the string argument is a number, AMB converts the number to a string and strips leading zeros as follows.

Coding Yields
&SUBSTR( 012, 1, 2) 12
&SUBSTR( -12, 1, 2) -1
&SUBSTR( -012, 1, 2) -1