Previous Application Programming: Strings Next

String Concatenation

The addition operator is used to concatenate strings. For example, the command:

A = 'This is' + ' a concatenation example.'  
PRINT, A  

results in the following output:

This is a concatenation example.  

Strings can also be broken across code lines:

Print, "This is a multi-line " $  
   + "string concatenation example."  

results in the following output:

This is a multiline string concatenation example.  

The following IDL statements build a scalar string containing a comma-separated list of the names found in the TREES string array:

; Create array of trees.  
trees = ['Beech', 'Birch', 'Mahogany', 'Maple', 'Oak', $  
         'Pine', 'Walnut']  
  
; Use REPLICATE to make an array with the correct number of commas   
; and add it to trees.  
names = trees + [REPLICATE(',', N_ELEMENTS(trees)-1), '']  
  
; Show the resulting list.  
PRINT, names  

Running the above statements results in the following output:

Beech, Birch, Mahogany, Maple, Oak, Pine, Walnut  

  IDL Online Help (March 06, 2007)