- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone,
I'm having problems figuring out why this does not work:
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!
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
string = string(1:6)//"goodbye"
In the second example, you make a string of 27 characters including blanks, then discard 7 blanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the reply... I didn't realize that the blanks counted. It makes a lot more sense now :)

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page