Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Concatenting Strings Help

Concatenting Strings Help

Concatenting Strings Help

I need to build a string based on some input data.  The data is coming from user input from a motif application so I don't know the length of any piece of data.  
Here is my code:

      character*50   str0,s0
      character*50   str1,s1
      character*50   str2,s2
      character*50   str3,s3
      character*10   str4,s4
      character*10   str5,s5
      character*70   elemID
      integer*4      lenchr

c  *** note: s0 thru s5 are variable from motif applic.***

      str0 = s0(1:lentrim(s0))
      str1 = s1(1:lentrim(s1))
      str6 = s6(1:lentrim(s6))

      elemID = str0 // ',' // str1 // ',' // str2 // ',' //
     &         str3 // ',' // str4 // ',' // str5

      open(1,"filename", status="UNKNOWN")
      write(1,'(a,2x,i4)') elemID, lenchr

c ***  end of code ***

When I print out the values, I get the correct values for all the separate variables, ie...  
str0 = base
str1 = A
str2 = B
str3 = C
str4 = D
str5 = E

When I print out 'eleID' and 'lenchr', I expect this:
'base,A,B,C,D,E  14'
... but what i get is:
'base  4'

I am assuming this has something to do with the string declarations, but I'm not sure.  I know that when all the strings are added up, they will be less than 70 characters, but I don't know the length of any of the particular fields.

Any help would be greatly appreciated.



RE: Concatenting Strings Help

Consider what you are concatenating. STR0 through STR3 are each length 50 characters. Concatenating just the first two (with that comma in between) overflows "elemID". You ought to do your LEN_TRIMming and concatenating all together:


That will eliminate all those trailing blanks, as well as save the auxilliary storage variables, which, as you coded them, wind up being exact copies (trim the blanks, then pad with blanks again to fill the variable to its defined length).

RE: Concatenting Strings Help

Whew! I got back here before someone else pointed out the flaw in my advice! When I awoke this morning, it dawned on me that in my suggestion to combine the trimming and concatenation, I mistakenly used LEN_TRIM (which returns the length with blanks trimmed), when I should have used just TRIM (which returns the trimmed string itself instead of the length). The revised line would be then this:


What an embarassment! But I hope I have redeemed myself. HTH.

RE: Concatenting Strings Help


Thanks for your help.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close