A character expression is an expression whose operands have the character type. It evaluates to a single value of type character, with a size of one or more characters. The only character operator is the concatenation operator, //.
Expression |
Meaning |
---|---|
a // z |
Concatenate a with z. |
The result of concatenating two strings is a third string that contains the characters of the left operand followed immediately by the characters of the right operand. The value of a concatenation operation a//z is a character string whose value is the value of a concatenated on the right with the value of z, and whose length is the sum of the lengths of a and z.
The operands can be any of the following kinds of data items:
Character constant
Character variable
Character array element
Character function
Substring
Structured record field (if it evaluates to a scalar character data item)
Examples: Character expressions, assuming C, S, and R.C are characters:
'wxy' 'AB' // 'wxy' C C // S C(4:7) R.C
Note the following (nonstandard) exceptions:@
Control characters--One way to enter control characters is to hold down the Control key and press another key. Most control characters can be entered this way, but not Control-A, Control-B, Control-C, or Control-J.
Example: A valid way to enter a Control-C:
CHARACTER etx etx = CHAR(3)
Multiple byte characters--Multiple byte characters, such as Kanji, are allowed in comments and strings.
The form of the character string assignment is:
v = e |
|
---|---|
e |
Expression giving the value to be assigned |
v |
Variable, array element, substring, or character record field |
The meaning of character assignment is to copy characters from the right to the left side.
Execution of a character assignment statement causes evaluation of the character expression and assignment of the resulting value to v.
If e is longer than v, characters on the right are truncated.
If e is shorter than v, blank characters are padded on the right.
Example: The following program below displays joinedDD:
CHARACTER A*4, B*2, C*8 A = 'join' B = 'ed' C = A // B PRINT *, C END
Also, this program displays the equal string:
IF ( ('ab' // 'cd') .EQ. 'abcd' ) PRINT *, 'equal' END
Example: Character assignment:
CHARACTER BELL*1, C2*2, C3*3, C5*5, C6*6 REAL Z C2 = 'z' C3 = 'uvwxyz' C5 = 'vwxyz' C5(1:2) = 'AB' C6 = C5 // C2 I = 'abcd' Z = 'wxyz' BELL = CHAR(7) Control Character (^G)
Variable |
Receiving Value |
Comment |
---|---|---|
C2 |
'zD' |
A trailing blank |
C3 |
'uvw' |
|
C5 |
'ABxyz' |
|
C6 |
'ABxyzz' |
The final 'z' comes from C2 |
I |
'abcd' |
|
Z |
'wxyz' |
|
BELL |
07 hex |
Control-G, a bell |
Example 4: A Hollerith assignment: @
CHARACTER S*4 INTEGER I2*2, I4*4 REAL R S = 4Hwxyz I2 = 2Hyz I4 = 4Hwxyz R = 4Hwxyz
Here are the rules for character assignments:
If the left side is longer than the right, it is padded with trailing blanks.
If the left side is shorter than the right, trailing characters are discarded.
The left and right sides of a character substring assignment cannot overlap. See the "Substrings" .