Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29276 Discussions

Character concatenation operator with character variables

john35802
Beginner
616 Views
I have CVF 6.6 Professional 6.6A. Why doesn't the character concatenation operator work with character variables. For example, consider the following code:

TEXT1 = ADJUSTL( TEXT1 )
TEXT1 = TRIM( TEXT1 )
TEXT2 = ADJUSTL( TEXT2 )
TEXT2 = TRIM( TEXT2 )
TEXT = TEXT1 // ' ' // TEXT2

Where all three variables were declared as character (256), and text1 and text2 were previously assigned values, then by what I have read in the language reference manual, the final result assigned to TEXT should contain what's in TEXT1, followed by a blank character, followed by what's in TEXT2. However, what actually happens is that TEXT is assigned what's in TEXT1 only. The complier also warns me that this line won't work. Is this behavior in accordance with Fortran 95, or is this a defect of CVF?
0 Kudos
2 Replies
wkramer
Beginner
616 Views
You should use:
TEXT=TRIM(ADJUSTL(TEXT1))//''//TRIM(ADJUSTL(TEXT2))

The statement:
TEXT1 = TRIM( TEXT1 )
still leaves you with a 256 character string.
Appending a string to the end doesn't contribute to the result because TEXT also has 256 characters

Walter
0 Kudos
john35802
Beginner
616 Views
Thankyou. That was it.
0 Kudos
Reply