User Tools

Site Tools


string_fixed_length_string_.htm
Navigation:  Language Reference > 3 - Variable Declarations > Data Types >====== STRING (fixed-length string) ====== Previous pageReturn to chapter overviewNext page

NewC7.jpg

      length        
label STRING ( string constant ) [,DIM( )][,OVER( )] [,NAME( )] [,EXTERNAL] [,DLL] [,STATIC]
      picture       [,THREAD] [,AUTO] [,PRIVATE] [,PROTECTED]

blk2blue.jpg

STRING A character string.

Format: A fixed number of bytes.

Size: 4MB

length A numeric constant, variable, or expression that defines the number of bytes in the STRING. String variables are not initialized unless given a string constant.
string constant The initial value of the STRING. The length of the STRING (in bytes) is set to the length of the string constant. The limit for string constants is 1024 characters.
picture Used to format the values assigned to the STRING. The length is the number of bytes needed to contain the formatted STRING.
DIM Dimension the variable as an array.
OVER Share a memory location with another variable.
NAME Specify an alternate, “external” name for the field.
EXTERNAL Specify the variable is defined, and its memory is allocated, in an external library. Not valid within FILE, QUEUE, or GROUP declarations.
DLL Specify the variable is defined in a .DLL. This is required in addition to the EXTERNAL attribute.
STATIC Specify the variable's memory is permanently allocated.
THREAD Specify memory for the variable is allocated once for each execution thread. Also implicitly adds the STATIC attribute on Procedure Local data.
AUTO Specify the variable has no initial value.
PRIVATE Specify the variable is not visible outside the module containing the CLASS methods. Valid only in a CLASS.
PROTECTED Specify the variable is not visible outside base CLASS and derived CLASS methods. Valid only in a CLASS.

STRING declares a fixed-length character string. The memory assigned to the STRING is initialized to all blanks unless the AUTO attribute is present.

It is now possible to declare STRING types of variable size to the compiler. Restrictions are the same as for variable-size arrays: declarations are available in the procedure or routine local scope only, and all variables used in the expression must be known at the time of the variable's creation. See Also: Variable Size Declarations

In addition to its explicit declaration, all STRING variables are also implicitly declared as STRING(1),DIM(length of string). This allows each character in the STRING to be addressed as an array element. If the STRING also has a DIM attribute, this implicit array declaration is the last (optional) dimension of the array (to the right of the explicit dimensions).

You may also directly address multiple characters within a STRING using the “string slicing” technique. This technique performs similar action to the SUB function, but is much more flexible and efficient (but does no bounds checking). It is more flexible because a “string slice” may be used on both the destination and source sides of an assignment statement and the SUB function can only be used as the source. It is more efficient because it takes less memory than individual character assignments or the SUB function.

To take a “slice” of the STRING, the beginning and ending character numbers are separated by a colon (:) and placed in the implicit array dimension position within the square brackets ([]) of the STRING. The position numbers may be integer constants, variables, or expressions. If variables are used, there must be at least one blank space between the variable name and the colon separating the beginning and ending number (to prevent PREfix confusion).

Example:

Name        STRING(20)                         !Declare 20 byte name field

ArrayString STRING(5),DIM(20)                  !Declare array

Company     STRING('SoftVelocity Corporation') !The software company - 20 bytes

Phone       STRING(@P(###)###-####P)           !Phone number field - 13 bytes

ExampleFile FILE,DRIVER('Clarion')             !Declare a file

Record       RECORD

NameField     STRING(20),NAME('Name')          !Declare with external name

            END

           END

 CODE

 NameField = 'Tammi'                          !Assign a value

 NameField[5] = 'y'                           ! change fifth letter

 NameField[5:6] = 'ie'                        ! and change a “slice”

                                              ! the fifth and sixth letters

 ArrayString[1] = 'First'                     !Assign value to first element

 ArrayString[1,2] = 'u'                       !Change first element 2nd character

 ArrayString[1,2:3] = NameField[5:6]          !Assign slice to slice

string_fixed_length_string_.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1