Rexx has two fundamental string concatenation operators.
Space concatenation is performed when two terms are separated by an intervening space.
Here is an example of space concatenation:
magic1 = 'open'
magic2 = 'sesame' say magic1 magic2
shows: open sesame |
In the above example the two magic words were concatenated with an intervening space.
Here is another example of space concatenation:
say 'The result of 2 + 2 is:' 2 + 2
shows: The result of 2 + 2 is: 4 |
In the above example the caption and the computation result were concatenated with an intervening space.
Space concatenation is also performed implicitly when an instruction is continued across a line boundary.
say 'abra' ,
'ca' , 'dabra' shows: abra ca dabra |
Often, you will want to concatenate the values without an intervening space. This is accomplished by adding an abuttal operator, at the front of the lines which follow the first.
say 'abra' ,
|| 'ca' , || 'dabra' shows: abracadabra |
There are several methods of performing an abuttal concatenation
Here is an example of abuttal concatenation, using the abuttal operator:
magic1 = 'jumpin'
magic2 = 'jehosephat' say magic1 || magic2
shows: jumpinjehosephat |
In the above example the two magic words were concatenated WITHOUT an intervening space.
Here is an example of abuttal concatenation, when one term is quoted:
magic1 = 'jumpin'
magic2 = 'jehosephat' say magic1'jehosephat' say 'jumpin'magic2
shows: jumpinjehosephat jumpinjehosephat |
Here is an example of abuttal concatenation, when the left term is a function result:
magic1 = 'shazam'
say left( "Today's magic word is:", 24 )magic2
shows: Today's magic word is: shazam |
Here is an example of abuttal concatenation, due to a comment between terms:
magic1 = 'jumpin'
magic2 = 'jehosephat' say magic1/* connect the magic words */magic2
shows: jumpinjehosephat |
An elaborate example of the string concatenation is:
/* get year, month, and day of month */
parse value date( 'Standard' ) with yr 5 . say right( time( 'Civil' ), 8) center( date( 'Month' ), 38 ), || substr( yr, 3 )'.'right( date( 'Dayofyear' ), 3, '0' ) shows a line similar to the following: 2:38pm July 02.189 |
The above example used the PARSE instruction
and the following built-in functions;
  CENTER,
  DATE,
  TIME,
  RIGHT,
  SUBSTR