replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - TRIM vs. TRIM@
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TRIM vs. TRIM@

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
Little-Acorn



Joined: 06 Jul 2008
Posts: 111
Location: San Diego

PostPosted: Fri May 27, 2011 11:54 pm    Post subject: TRIM vs. TRIM@ Reply with quote

I have used the function TRIM many times to get rid of trailing blanks, and have found that it works as advertised.

I note a different command TRIM@, which is a subroutine instead of a function. The "Help" file for FTN95 says that TRIM@ will remove the LEADING blanks (not trailing blanks) from a string. Says that in two different places in the "Help" file entry. I'm convinced.

But at the bottom of the "Help" file entry for the subroutine TRIM@ is the sentence:

Notes . . . . The standard intrinsic function TRIM can be used instead.

I thought the function TRIM removed TRAILING blanks, not leading blanks. In fact, I know it does. Why does this part of the "Help" file say it can be used in place of the subroutine TRIM@ which removes LEADING blanks? Typo in the "Help" file?')
Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: D�sseldorf, Germany

PostPosted: Sat May 28, 2011 6:57 am    Post subject: Reply with quote

To avoid confusions with trim, I prefer adjustl and adjustr which are standard Fortran functions.

Code:
string = '   abcd   '
string2 = adjustl(string) ==> 'abcd      '
string2 = adjustr(string) ==> '      abcd'

Regards - Wilfried
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Sat May 28, 2011 5:43 pm    Post subject: Reply with quote

You're correct, TRIM removes trailing blanks, TRIM@ removes leading blanks.

Its a mistake in the help file.

TRIM@ is really an alternative to the standard intrinsic ADJUSTL so the HELP file should say that ADJUSTL can be used instead of TRIM@.

Using T = TRIM(S) is not as useful as you might think, since there will still be trailing blanks unless the length of the character variable is LEN_TRIM(S). Unfortunately you cannot allocate character arrays to be a particular length at run time (well, not in Fortran 95). About the only place I find TRIM helpful is to remove trailing blanks on output.
Back to top
View user's profile Send private message
Little-Acorn



Joined: 06 Jul 2008
Posts: 111
Location: San Diego

PostPosted: Sat May 28, 2011 6:08 pm    Post subject: Reply with quote

Thank you, Wilfried and david! I thought that was the case.

I seldom use TRIM into a storage location, for the reasons you cite. But it is useful directly.

CHARACTER*2000 CNAME
READ(5) CNAME
I=INDEX("David and Goliath", TRIM(CNAME))
IF(TRIM(CNAME).EQ."David") NNAMES=NNAMES+1
PRINT*,TRIM(CNAME)," is my friend's name."

etc.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group