FORTRAN 77 Language Reference

Character Expressions

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:

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:@

Character String Assignment

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.

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)

The results are:

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 

Rules of Assignment

Here are the rules for character assignments: