next up previous contents index
Next: Character Intrinsic Functions Up: Character Handling and Logic Previous: Character Expressions

Character Assignment Statements

  The character assignment statement has the general form:
char-var = character-expression
where char-var can be a character variable, array element, or substring.

There is one important restriction on character assignment statements: none of the characters being referenced in the expression on the right may be defined in char-var on the left, that is to say there can be no overlap. Thus the assignment statement:
STRING(1:N) = STRING(10:)
is valid only as long as N is no higher than 9. It is, of course, easy to get around this restriction by using a temporary character variable with a suitable length.

Note when a value is assigned to a substring (as in the last example) the other characters in the parent string are not affected at all. If the string was previously undefined then the other character positions will still be undefined; otherwise they will retain their previous contents.

The expression and the character object to which its value is assigned may have different lengths: if the expression is longer then the excess characters on the right are lost; if it is shorter then blanks are appended. Care is needed to declare adequate lengths or else the results can be unexpected:

 
      CHARACTER AUTHOR*30, SHORT*5, EXPAND*10 
      AUTHOR = 'SHAKESPEARE, WILLIAM' 
      SHORT = AUTHOR 
      EXPAND = SHORT
The resulting value of EXPAND will be 'SHAKE ' where the last five characters are blanks.


next up previous contents index
Next: Character Intrinsic Functions Up: Character Handling and Logic Previous: Character Expressions
Helen Rowlands
8/27/1998