The STRING predefined schema provides a way of declaring
variable-length character strings. The compiler stores STRING
data as though it were stored in the following schema
definition:
TYPE
STRING ( Capacity : INTEGER ) = VARYING[Capacity] OF CHAR;
The syntax of the discriminated schema is as follows:
STRING ( Capacity )
The 'Capacity' is an integer in the range 1..65,535 that
indicates the length of the longest possible string.
To use the predefined STRING schema, you provide an upper bound
as the actual discriminant. Consider the following example:
VAR
Short_String : STRING( 5 ); {Maximum length of 5 characters}
Long_String : STRING( 100 ); {Maximum length of 100 characters}
You can assign string constants to STRING variables from length
0 to the specified upper bound. The compiler allocates enough
storage space to hold a string of the maximum length. A STRING
variable with length 0 is the empty string (''). You can only
use character-string constants (or expressions that evaluate to
character strings) to assign values to variables of these types;
you cannot use standard array constructors.
You can access the CAPACITY predeclared identifier as you would
a schema discriminant, and you can access the LENGTH and BODY
predeclared identifiers as you would access fields of a record.
The CAPACITY identifier allows you to access the actual
discriminant of the STRING schema; the LENGTH identifier allows
you to access the current length of the string object; and the
BODY identifier contains the current string object, including
whatever is in memory up to the capacity of the discriminated
schema.