Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29284 Discussions

Problem with string concatenation

alexism
Beginner
840 Views
Hi everyone,

I'm having problems figuring out why this does not work:

program test
implicit none
character*20 :: string
string="hello"
string=string//"goodbye"
print*,string
end program test

Why doesn't the "goobye" get appended? If I reverse the order of the
concatenation, it does work:

program test
implicit none
character*20 :: string
string="hello"
string="goodbye"//string
print*,string
end program test

Thanks!
0 Kudos
2 Replies
TimP
Honored Contributor III
840 Views
Your first example pads string out to 20 characters including blanks. When you append "goodbye" you have a string of 27 characters. You assign the first 20 characters to string and lose the remaining characters. You may be looking for something like
string = string(1:6)//"goodbye"

In the second example, you make a string of 27 characters including blanks, then discard 7 blanks.
0 Kudos
alexism
Beginner
840 Views
Thanks for the reply... I didn't realize that the blanks counted. It makes a lot more sense now :)
0 Kudos
Reply